Using Salesforce SOAP API from Java Code

Recently i had to develop a portlet that talks to SalesForce.com and retrieves some data. I decided to use the SalesForce SOAP API for that, i followed these steps
  1. First step is to get your salesforce.com security token, follow steps as described in Generating Security Token for SalesForce.com post for that
  2. Second step is to login into your salesforce.com account and download the Enterprise .wsdl, Follow steps 1-3 from Accessing SalesForce data using SOAP Service - SoapUi post for that
  3. You should use the Force.com web services connector (WSC) which has helper code that simplify working with Force.com SOAP service.
  4. Once you have WSC project downloaded on your machine and complied into jar copy it in a directory and then also copy your enterprise.wsdl in the same directory, then execute
    
    java -classpath target/force-wsc-29.0.0-jar-with-dependencies.jar com.sforce.ws.tools.wsdlc enterprise.wsdl enterprise.jar
    
    It will generate enterprise.jar file for you
  5. Now create a Java Project and add both enterprise.jar and force-wsc-29.0.0-jar-with-dependencies.jar in your classpath
  6. Last step is to create SFDClient.java class like this Replace userId, password and securitytoken in this file with the values you have
  7. When you run the SFDClient.java class it will display list of contacts in your salesforce.com account

3 comments:

Anonymous said...

Hi Sunil,
The soap enterprise connector package is missing when I follow these steps. Can you let me know if it worked for you the first time?
Thanks
Raghu

Abhi said...

Thanks for info....
Website development in Bangalore

KITS Technologies said...

Oh man! This blog is sick! How did you make it look like this !
P0wer bi onlinetraining from india