Tuesday, July 23, 2013

Writing Unit Tests...For everything in SFDC!

Unit tests have been covered on tons of different blogs by tons of way more qualified developers but I figured I'd write an entry which compiles all the best info I have found around the net.  I really like to reference my own blog as a resource master, so this will help a future me out, as well! :)

 First and foremost is the official Developer force page on writing good unit tests, which can be found HERE.  It talks about structure and what to do and not to do.

Second I would recommend going over the information found HERE, regarding the IsTest annotation.  This covers @isTest(SeeAllData=true) , which is a must have if you have to write code against things like the PriceBook2, which will return no rows during tests.

Next I would check out the usual suspects where good coding examples can be found.  Places like Jeff Douglas's blog.  He has a nice entry on writing Unit Tests f  or Visual Force Controller Extensions, which can be found HERE.  Another really good reference is Tquila Team, and they cover a bunch of cool topics on writing Unit Tests, HERE.

One other thing to be aware of is, test.isRunningTest() for your controller or trigger code.  Sometimes if you don't want a section of code to be hit by a test you can wrap it in an If statement testing this system test method.  The details about it can be found on the test method's page, HERE.  Along with a lot of other useful info regarding the test class and its methods.

I figure I should include some code in this posting so, I'll write a Unit Test for both a standard trigger  and a Visual Force page, which will instantiate its Custom Controller/Extension...I guess I'll put a snippet for both, since an extension has to have the Standard Object passed to it, as seen in JD's blog posting.  More later....






     
            
           
     

Wednesday, June 26, 2013

SFDC WSC Repository : MVN

Salesforce, seems to have moved the WSC builds from GitHub over to MVNRepository.  All builds can be found here:

http://mvnrepository.com/artifact/com.force.api


Tuesday, April 2, 2013

Visualforce : Using Maps in PageBlockTables...

So I had never used a Map in a PageBlockTable before. Today I did. I'll reference this Blog, since this is where I stumbled on the info. Harshesh's Blog Apparently the key is to use Value[var] to access the data in the map, within the visualforce pageblocktable. Here is an example:

     
            
           
     

if you are using a custom class in your controller or extension then it would look something like this:

Now, why would you want to do this? I'll give you a full blown example here. Let's say you want to do some work on the selected row and you need the whole rows data: ..will update later with this!

Friday, March 8, 2013

Testing Google prettyPrint...

This is a test page with some code on it!

Here is the code:


function myFunc(cb){ if($(cb).is(':checked')){ //alert("checked!!!"); $('input[name$="oliCheck"]').prop("checked",true); }else{ $('input[name$="oliCheck"]').prop("checked",false); } //console.log(tName); }

Thursday, March 7, 2013

Generating a WSDL from Salesforce and then generating Java libraries (JAR)....

The first thing you have to do is make sure your Java (JDK) development environment is all set up.  I have a short guide to doing this here: http://anotherforceblog.blogspot.com/2013/03/setting-up-jdk-se616-and-eclipse-for.html

Once you are all good to go and can at the very lest, type java at the command prompt without getting an error follow these general steps:

The First thing you will need to go do is to get the Force.com Web Service Connector (WSC).  You can find it here:

http://code.google.com/p/sfdc-wsc/downloads/list

I will be using wc-23.jar for this.

Save this file into your "lib" folder, ie:

C:\Program Files (x86)\Java\jdk1.6.0_43\lib

First things first.  I have had issues downloading WSDL's using Chrome.  FireFox and IE both seem to get them correctly.  I'll go through the steps using Firefox as any little thing seemed to throw errors for me while building the libraries.

First log into Salesforce and then goto "Your Name" > Setup > Develop > API

Select the WSDL you want to generate by clicking on the link under the WSDL type, I am generating an Enterprise WSDL for this.

The next screen will list all of the packages installed in your org, you can review the verson settings for each if there are any.

When you are ready, click the "Generate" button.

You'll be redirected to wsdl.jsp page which is an XML document.

Now Save this, in Firefox : Save Page As > Now Firefox is going to have a name already populated in the save field, delete it and name it on your own.  If you save it or rename it with the.wsdl extension FF put on it, it will save as a .wsdl.xml file and will cause the wsc program to fail (no such file found etc..)

Select your save location and click save

Once your file has been saved open up a CMD prompt and navigate to the folder that has your .wsdl file in it.  The easiest way to do this is to navigate to the location in explorer and then copy the address out of the address bar and then go into your cmd window, type CD <space> and then right click and select paste and hit enter



Now that you are in the directory, you will need to run the following (similar different version/type) command to generate the library.jar:

java -classpath "C:\Program Files (x86)\Java\jdk1.6.0_43\lib\wc-23.jar;C:\Program Files (x86)\Java\jdk1.6.0_43\lib\tools.jar" com.sforce.ws.tools.wsdlc enterprise.jar entlib.jar

The breakdown for this is: java -classpath "<directory with wsc-2*.jar>;<directory with jdk tools.jar>" com.sforce.ws.tools.wsdlc <wsdl filename> <jar output name>



If everything was in the right place and all the files were correct you should have a new jar file named whatever you named it in the directory with your WSDL file.




Setting up JDK SE6(1.6) and Eclipse for SalesForce webservice development...



1: install jdk 1.6
Check to see which version of Java you have installed (ie 32 or 64 bit)  you may need to uninstall and reinstall the Java RTE (by installing the JDK): (Control Panel > Java (32/64 bit)
Download from here:

2: Next, download and install Eclipse Juno IDE for Java EE Dev (32 or 64 bit, depends on which RTE/JDK you have installed)

3:  Before you can compile and run Java code using “-classpath” you will need to add the path to your system path (this will resolve any java not recognized as an internal or external command errors from the command prompt):
Right click Computer : Advanced System Settings : Environment variables >  System Variables > Path :
Make sure you have the lib and bin paths (this will be dependent on how you have java installed/version etc.) added to this with a semi colon separating them ie:
Example:  C:\Program Files (x86)\Java\jdk1.6.0_43\lib;C:\Program Files (x86)\Java\jdk1.6.0_43\bin;

4:  After adding that to the Path value and clicking “OK”, you may want to add a new variable: CLASSPATH
This will again be the same thing that you just added to the Path variable. IE:
Example: C:\Program Files (x86)\Java\jdk1.6.0_43\lib;C:\Program Files (x86)\Java\jdk1.6.0_43\bin;

Make sure to click OK at each window so your changes take effect!!

4b:  You can test to see if this worked by opening a command prompt and typing, “java” (without the quotes), it should return a usage menu.

5:  You will probably also want to download SOAPUI as well.  You can get it here:
I went with the eclipse plug in.
You should be ready to go with Java development now (ie web services and such)