Integration between Java app and Salesforce – Partner WSDL

It is very common for any Salesforce developer to come across scenarios involving integrationsalesforcecodes logo between Salesforce and other systems. Most of these systems are based on JAVA. In this post we will cover how to integrate between Salesforce and a locally running Java application. The same logic and code can be used to connect to Salesforce from a web based java application also.

Steps to integrate

1) Download Partner WSDL from your sandbox 

    You can find Partner WSDL in your salesforce sandbox under Setup – Develop – API. Download partner WSDL file from above location to your local system folder.

2) Get WSC (Webservice connector) jar file provided by salesforce.  

    This jar file was initially provided by salesforce as .jar itself. Force.com webservice connector is a high performance webservice client stack implemented using a streaming parser. This gives some advantages compared to regular java classes generated from partner WSDL using other WSDL to Java tools. You can find source code to latest version of source code in force.com WSC github.

First clone the repository to your system and then build jar file using the instructions given.

3) Generate Partner.jar using WSC (Webservice connector) jar generated in step 2  

    You can convert partner WSDL into a jar file using WSC jar file. It is single command from command line, which can be found in the above github link.

4) Create project in eclipse 

    By the end of step 3 you have all the components needed for connecting to salesforce. Now create a new java project in eclipse. Import wsc.jar from step 2 and partner.jar from step 3 as external libraries. Then create a new class with name “PartnerExample” in the project. Then copy paste the code below,

It should compile without any error. Use Runas Java application option in eclipse to run the project. This code queries 5 contact and creates an account

Reference links

There is lot of good resources demonstrating similar connectivity options between salesforce and java applications. Please check below links,