How do you connect to Salesforce from an external application, say, for example, Java? If you Google for the information, you will quickly learn that Salesforce provides different methods and different APIs. But what you will probably not find is a step-by-step guide teaching you exactly how to do it. In this blog post, I have stitched together a complete step-by-step instructions with screenshots on how to download, install, configure and use Salesforce’s SOAP API to connect from a java program and execute some basic transactions (query, insert, update, delete records). In less than 60 minutes, you will have a fully functional java program that will connect to Salesforce and execute transactions in Salesforce.
The guide includes downloading necessary WSDLs from Salesforce, creating & packaging the required components in a JAR file, referencing the JAR file in your java program, logging on to Salesforce from the java program, querying and manipulating data. Here is an overview of steps that need to be completed and is covered in the guide
- Install Java
- Install Eclipse
- Install Force.com WSC (Web Services Connector)
- Install Maven
- Generate JAR Files
- Download WSDL Files From Salesforce
- Generate Java Stub File
- Create Java Program
- Execute Transactions using SOAP API
(Once you are done with this, you may also want to explore my other blog post Step-By-Step Guide to Get Started with Salesforce REST API using Java to learn how to get started with Salesforce REST API using Java or explore A 60 Minutes Step-By-Step DIY Guide to Salesforce REST API for Non-Developers to get started with REST API without going through the hassles of writing a Java program)
Even if you are not a developer, you should be able to follow the guide and have working java program at the end of it. Sounds interesting? Download the following presentation and let’s get started…
Here is the URL to get the code used in this guide
- Java program to connect to test connecting to Salesforce
- Java program to query, create, update & delete records in Salesforce
In these codes, I have used simple SOAP API calls like query(), create(), update() & delete() to give you a taste of how to use APIs. For complete reference on Salesforce SOAP API listing all calls, objects, fields and other details please refer to SOAP API Developer’s Guide
Not only this, you can go a step further and use other SOAP/WSDL based APIs that Salesforce provides to extract and manipulate data and metadata. For a list of different APIs along with a brief explanation on which API should be used when, please navigate to URL https://help.salesforce.com/HTViewHelpDoc?id=integrate_what_is_api.htm
Other References:
- Setting Up Your Java Developer Environment – https://help.salesforce.com/help/pdfs/en/salesforce_developer_environment_tipsheet.pdf
- Introduction to the Force.com Web Services Connector – https://developer.salesforce.com/page/Introduction_to_the_Force.com_Web_Services_Connector
October 24, 2019 @ 8:30 PM
Jar Problem fix that I encountered
———————————–
When compiling the enterprise.jar the maven was failing and not building the jar.
Had to explicitly add skiptests tag
maven-surefire-plugin
2.12.4
True
October 24, 2019 @ 8:53 PM
Thanks for sharing Rajesh
August 25, 2019 @ 4:46 PM
Wonderful article Agarwal. Worked like a charm!
August 28, 2019 @ 7:15 AM
Thanks for your feedback, Abdul. Glad to know that. 🙂
July 27, 2019 @ 5:45 AM
I cannot import com.sforce.soap.metadata, it doesn’t exists
July 27, 2019 @ 2:32 PM
Never mind, i did the same process with Meteadata WSDL instead of Enterprise
April 4, 2017 @ 6:50 AM
Thanks Ashish, this was very helpful and easy to follow.
-Kevin
April 4, 2017 @ 6:49 AM
If you are on windows and having trouble creating the jar file please reference the following to disable the tests in maven.
http://mauricekremer.dscloud.me/force-com-generating-the-wsc-from-source/
December 3, 2017 @ 6:44 PM
Hi Kevin,
The link you have provided is not working.
Narendra
March 24, 2017 @ 12:51 PM
Good Post Asish….how can i run above commands in windows 7(64-bit)…what is the procedure for windows 7..
August 27, 2016 @ 5:07 PM
In the original article “Introduction to the Force.com Web Services Connector”, everything works just fine code-wise, except that the WCS Metadata API Java code sample generates two syntax errors …
Line 54: AsyncResult[] ars = metadataConnection.create(new CustomObject[] { co });
– The method create(CustomObject[]) is undefined for the type MetadataConnection
Line 72: arsStatus = metadataConnection.checkStatus(ids);
– The method checkStatus(String[]) is undefined for the type MetadataConnection
This occurs using the “force-wsc-38.0.0-uber.jar” jar file. Can you kindly tell me what I need to do to fix these errors? Cheers,
David
July 26, 2016 @ 4:00 AM
@Nagendra Nagarajayya – the code is missing some hard returns. For the update() and delete() functions, the first several lines of each function are on the same line as the commented-out explanation of what the function does. This causes those lines to appear commented out to Eclipse. If you put in some hard returns where the functions start, you should be able to save without errors.
I did have one question – when I save the Java class and attempt to run it, I receive an error: “Selection does not contain a main type.” Did anyone receive this error and manage to resolve it? Thank you!
May 27, 2016 @ 6:24 PM
Unable to generate TARGET folder on Windows 7 64 bit machine. Got stuck on step no. 5. Please help.
May 27, 2016 @ 6:21 PM
Unable to generate Target Folder and .Jar File in Step No 5 Please guide me.
May 27, 2016 @ 6:17 PM
Unable to generate target folder and Jar file on step No. 5 please suggest me.
May 14, 2016 @ 4:24 AM
Very nice article; very useful. Allowed me to get started with salesforce apis very easily.
I did find a problem, not sure if it is specific to me (tried on firefox and chrome) ; the second example query/create/insert/delete code seems to be truncated and the last line is 151, it should have more lines as the insert/delete methods are missing.
March 26, 2016 @ 6:05 PM
great post with step by step guide, any way keep on writing more info
March 27, 2016 @ 2:18 PM
Thanks Jessica !
January 30, 2016 @ 11:08 AM
Thanks! This was easy to follow and I feel like I learned something! My next challenge is to have Salesforce call my SOAP API to trigger an action and response…
November 24, 2015 @ 1:52 AM
Wonderful explanation step by step…
July 23, 2015 @ 2:24 PM
Excellent article! Again, much better than the salesforce documentation. Thank you very much for taking the time to prepare such good content!
July 23, 2015 @ 4:13 PM
Thanks Pablo, appreciate your appreciation. 🙂
July 10, 2015 @ 2:34 AM
Very good effort. Thanks a lot
May 29, 2015 @ 8:59 PM
Good tutorial, step by step, nice for me who want to started from beginning.