Salesforce Developer Environment Tipsheet
DOWNLOAD
First things first !
To download this implementation guide, click the download button below.
If you need more information about the implementation guide, you can read the Table of Contents below.
SETTING UP YOUR JAVA DEVELOPER
ENVIRONMENT
Summary
Configure your local dev
environment for integrating
with Salesforce using Java
This tipsheet describes how to set up your local environment so that you can start using Salesforce APIs
such as SOAP API or REST API
Note If youre setting up a local environment to develop Salesforce applications using Apex and
custom Metadata API components take a look at the Salesforce Extensions for Visual Studio Code
This tipsheet focuses on tools and configurations youll need to set up your local development system It
assumes you already have a working Salesforce organization with the API Enabled permission API is
enabled by default on Developer Edition Enterprise Edition Unlimited Edition and Performance Edition
organizations
To create a Developer Edition org go to developersalesforcecomsignup and follow the
instructions for signing up for a Developer Edition organization
If you have a Salesforce organization you can use for development but need to set up a sandbox for
development and testing see Deploy Enhancements from Sandboxes in Salesforce Help
Installing Java
You need the Java Developer Kit JDK version or later to use Salesforce APIs Java is a robust
crossplatform widely used language that integrates well with Salesforce
To install the JDK you need a Windows Mac OS X or Linux system that has internet access Depending
on your system you might also need administrator level access to install the JDK
Note If you think you already have the JDK installed use the steps listed in Verifying your JDK
install to verify your version of Java Most versions of Mac OS X and Linux come preinstalled with
a version of the JDK
The JDK is a development kit required to build Java applications The JDK includes the Java Runtime
Environment JRE which is required to run Java applications
Navigate to httpwwworaclecomtechnetworkjavajavasedownloadsindexhtml in your browser
on your local system Download the latest version of the JDK for your operating system Make sure
you are downloading the JDK and not the JRE
On Windows doubleclick the installer executable and follow the steps to install the JDK and the
included JRE to your local machine On Mac OS X open the dmg file and doubleclick the installer
package On Linux if you downloaded an rpm file in a command prompt window type rpm ivh
jdk install rpm file If you downloaded a tar file extract the files from the tar archive and
copy to a location of your choice
Add the JDK executables to your path
a On Windows click Start Control Panel System and Security System Advanced
system settings Click Environment Variables and find the PATH variable in System variables
Add the location of the bin folder of the JDK installation path to the end of your path value
Your path might look something like
SystemRootsystemSystemRootCProgram
FilesJavajdkxbin Click Ok to apply the changes
Last updated November
Setting Up Your Java Developer Environment
Installing Eclipse
b On Mac OS X or Linux you must update your PATH environment variable On Mac OS X you
can also use the javahome command to set your Java paths
Verifying your JDK install
To verify your JDK install in a command prompt window type java version You should see
something like
java version
JavaTM SE Runtime Environment build b
Java HotSpotTM Bit Server VM build b mixed mode
You can also verify that the Java compiler was properly installed by typing javac version in a
command prompt window The output should look something like
javac
If you get an error indicating that either java or javac is an unknown executable your installation might
have failed or you might not have set your path environment as described in Step
Installing Eclipse
Eclipse is an integrated development environment IDE for Java development
Eclipse requires a Java runtime environment to run
While Eclipse is not required to develop integration applications for Salesforce install Eclipse if you want
an easy to use IDE that works with Salesforce
Navigate to httpwwweclipseorgdownloads in your browser Download Eclipse IDE for Java
Developers Choose either the bit version or the bit version depending on the version of the
JDK you have installed
Unarchive the downloaded file to a location of your choice Eclipse does not have a special installation
application
Launch the Eclipse executable in the eclipse folder you just unarchived On Windows this is
eclipseexe on Mac OS X this is Eclipseapp and on Linux this is eclipse Eclipse will
ask for the location of a new eclipse workspace Click Ok to accept the default workspace location
Dismiss the welcome page by closing the welcome page window You are now in the Eclipse
workbench ready to create a new Javabased Salesforce integration project
Picking a Path Based on Which API You Use
The next steps for setting up your development environment depend on which Salesforce API you want
to use
To use SOAP API or CRUDbased Metadata API or any other WSDLbased Salesforce API complete the
steps in the following tasks
Install the Web Services Connector WSDLBased APIs on page
Download Developer WSDL Files WSDLBased APIs on page
Generating Java Stub Files WSDLBased APIs on page
Verify the WSDL Environment WSDLBased APIs on page
Setting Up Your Java Developer Environment
Install the Web Services Connector WSDLBased APIs
To use REST API Bulk API Connect REST API or any other RESTbased Salesforce API complete the steps
in the following tasks
Installing HttpClient and JSON Frameworks RESTBased APIs on page
Setting Up Connected App Access RESTBased APIs on page
Verify the REST Environment RESTBased APIs on page
Tooling API provides both SOAP and RESTbased interfaces so depending on your needs you can set up
your environment by using one of the paths above
Streaming API requires installing additional Java frameworks for supporting push technology See Example
Subscribe to and Replay Events Using a Java Client EMP Connector in the Forcecom Streaming API
Developers Guide
Install the Web Services Connector WSDLBased APIs
The Lightning Platform Web Services Connector WSC is a highperformance runtime framework that
makes using WSDLbased Salesforce APIs easier To install the WSC download the prebuilt jar file from
the Force MVN repository
Before you use the WSC framework make sure that you have a working of the Java JDK
Navigate to httpsmvnrepositorycomartifactcomforceapiforcewsc in your browser
Select the WSC version you want to download We recommend downloading the version that matches
the API version of Salesforce that youre using
To view all files select View All
Note If you cant find a prebuilt version of WSC that works with the API version youre using
you can build the jar file from source Navigate to httpsgithubcomforcedotcomwsc and
follow the instructions on Building WSC
Download the file ending in uberjar For example download the
forcewscuberjar file
Save the WSC jar file in a known location You use it to generate stub files with the WSDLs from your
Salesforce organization
Download Developer WSDL Files WSDLBased APIs
Salesforce Web Services Definition Language WSDL files provide API details that you use in your developer
environment to make API calls
To download WSDL files directly from your Salesforce organization
Log in to your Salesforce developer organization in your browser
From Setup enter API in the Quick Find box then select API
Download the appropriate WSDL files for the API you want to use
a If you want to use SOAP API youll need either the Enterprise or Partner WSDL See Choosing a
WSDL in the SOAP API Developer Guide to determine which WSDL to download
b If you want to use Metadata API youll need the Metadata WSDL To login and authenticate with
Salesforce youll also need either the Enterprise or Partner WSDL
Setting Up Your Java Developer Environment
Generating Java Stub Files WSDLBased APIs
c If you want to use Tooling API youll need the Tooling WSDL To login and authenticate with
Salesforce youll also need either the Enterprise or Partner WSDL
Generating Java Stub Files WSDLBased APIs
To use WSDLbased Salesforce APIs with Java you need to generate jar stub files that you can use in your
Java projects
Youll need the WSC jar file to generate stub files Youll also need the appropriate WSDL files for the API
you plan to use
Open a command prompt window and navigate to the location where your WSDL and WSC jar files
are
Generate the Java stub for the WSDL by using the following command in a command prompt window
java classpath path to WSC jarWSC jar filename
comsforcewstoolswsdlc path to WSDLWSDL filename path to
output stub jar and filename You might need to also include additional jar files that
WSC needs such as Rhino or StringTemplate in the classpath list separated by semicolons on
Windows or colons on MacLinux See Install the Web Services Connector WSDLBased APIs for
more information on Rhino and StringTemplate
An example Windows command for generating the stub jar file enterprisestubjar using the API version
WSC and the Enterprise WSDL might look something like this
java classpath testWorkspacewscforcewscjar
testWorkspacerhinoRjsjar
testWorkspacestringTemplateSTjar
jdkjdklibtoolsjar
comsforcewstoolswsdlc
testWorkspacewsdlenterprisewsdl
testWorkspacestubenterprisestubjar
Note that this example includes the Rhino and StringTemplate dependent jar files in the classpath
Verify the WSDL Environment WSDLBased APIs
You can verify your developer environment with a simple Java test application in Eclipse
You should have the JDK Eclipse and WSC installed and have generated the Java stub jar files for the
WSDL files that you need to use Youll need the stub jar file for either the Enterprise or Partner WSDL to
follow the verification steps
Run Eclipse Click File New Java Project and name the project SFWSCTest
Add the WSC and stub jar files to your project Click Project Properties Java Build Path
Libraries click Add External JARs select the WSC and stub jar files and click OK
Add a new folder to the src folder by rightclicking src then select New Folder and use wsc
as the folder name
Create a new class by rightclicking wsc and selecting New Class Name the class Main
Replace the code Eclipse generates for Mainjava as described in the following section
Use the following simple login example code for your Mainjava class Replace YOUR DEVORG
USERNAME with your developer organization username and replace YOUR DEVORG PASSWORD
Setting Up Your Java Developer Environment
Verify the WSDL Environment WSDLBased APIs
AND SECURITY TOKEN with your developer organization password appended with your security
token If you did not set a security token in your organization just provide your password A GitHub Gist
of this code is available here httpsgistgithubcomanonymousdcccfeeef
package wsc
import
import
import
import
comsforcesoapenterpriseConnector
comsforcesoapenterpriseEnterpriseConnection
comsforcewsConnectionException
comsforcewsConnectorConfig
public class Main
static final String USERNAME YOUR DEVORG USERNAME
static final String PASSWORD YOUR DEVORG PASSWORD AND SECURITY
TOKEN
static EnterpriseConnection connection
public static void mainString args
ConnectorConfig config new ConnectorConfig
configsetUsernameUSERNAME
configsetPasswordPASSWORD
try
connection ConnectornewConnectionconfig
display some current settings
SystemoutprintlnAuth EndPoint
configgetAuthEndpoint
SystemoutprintlnService EndPoint
configgetServiceEndpoint
SystemoutprintlnUsername configgetUsername
SystemoutprintlnSessionId configgetSessionId
catch ConnectionException e
eprintStackTrace
The following example output shows a typical successful run of this code
Auth EndPoint httpsloginsalesforcecomservicesSoapc
Service EndPoint
httpsyourInstancesalesforcecomservicesSoapcDULf
Username testusertestorgcom
SessionId DUQfARoAQDjpkHNReBpvBLZaDbgYMvsociUu
If the verification Java project runs and displays output that matches your organization your developer
environment is set up and you can start developing Java applications that integrate with Salesforce
Setting Up Your Java Developer Environment
Installing HttpClient and JSON Frameworks RESTBased APIs
Installing HttpClient and JSON Frameworks RESTBased
APIs
To access REST resources youll need to install HttpClient and JSON frameworks HttpClient lets you access
HTTP resources The JSON framework lets you generate and parse JSON request and response data
Youll need to have the JDK installed on your local system to use the HttpClient and JSON frameworks
Navigate to httphcapacheorgdownloadscgi in your browser and download the binary archive of
the latest GA version of HttpClient Unarchive the downloaded file and move the directory to a
location youll remember
Navigate to httpmvnrepositorycomartifactorgjsonjson in your browser and download the latest
binary jar file Copy this jar file to a location youll remember
Setting Up Connected App Access RESTBased APIs
Because Salesforce REST APIs use OAuth authentication create a connected app to integrate your
application with Salesforce
A connected app integrates an application with Salesforce using APIs Connected apps use standard SAML
and OAuth protocols to authenticate provide single signon and provide tokens for use with Salesforce
APIs In addition to standard OAuth capabilities connected apps allow Salesforce admins to set various
security policies and have explicit control over who can use the corresponding apps
Specify basic information about your app See Configure Basic Connected App Settings in Salesforce Help
Next provide OAuth settings See See Enable OAuth Settings for API Integration in Salesforce Help
For more information see Create a Connected App in Salesforce Help
Verify the REST Environment RESTBased APIs
You can verify your developer environment with a simple Java test application in Eclipse
You should have the JDK Eclipse and the HttpClient and JSON frameworks installed
Run Eclipse Click File New Java Project and name the project SFRESTTest
Click Project Properties Java Build Path Libraries and click Add External JARs Add the
HttpClient jar files httpclient httpcore commonscodec and commonslogging
the jar files will have version information in the filenames Add the JSON jar file which might also
have a version number in the jar filename
Add a new folder to the src folder by rightclicking src then select New Folder and use
sfdcrest as the folder name
Create a new class by rightclicking sfdcrest and selecting New Class Name the class Main
Replace the code Eclipse generates for Mainjava as described in the following section
Use the following simple login example code for your Mainjava class Replace YOUR DEVORG
USERNAME with your developer organization username and replace YOUR DEVORG PASSWORD
SECURITY TOKEN with your developer organization password appended with your security token
If you did not set a security token in your organization just provide your password Replace YOUR OAUTH
CONSUMER KEY with the consumer key from your development organizations connected app Replace
YOUR OAUTH CONSUMER SECRET with the consumer secret from your development organizations
Setting Up Your Java Developer Environment
Verify the REST Environment RESTBased APIs
connected app A GitHub Gist of this code is available here
httpsgistgithubcomanonymousfcbbcefcefbeb
package sfdcrest
import javaioIOException
import
import
import
import
import
import
orgapachehttpclientmethodsHttpPost
orgapachehttpimplclientDefaultHttpClient
orgapachehttpHttpResponse
orgapachehttpHttpStatus
orgapachehttputilEntityUtils
orgapachehttpclientClientProtocolException
import orgjsonJSONObject
import orgjsonJSONTokener
import orgjsonJSONException
public class Main
static final String USERNAME
static final String PASSWORD
TOKEN
static final String LOGINURL
YOUR DEVORG USERNAME
YOUR DEVORG PASSWORD SECURITY
httpsloginsalesforcecom
static final String GRANTSERVICE
servicesoauthtokengranttypepassword
static final String CLIENTID
YOUR OAUTH CONSUMER KEY
static final String CLIENTSECRET YOUR OAUTH CONSUMER SECRET
public static void mainString args
DefaultHttpClient httpclient new DefaultHttpClient
Assemble the login request URL
String loginURL LOGINURL
GRANTSERVICE
clientid CLIENTID
clientsecret CLIENTSECRET
username USERNAME
password PASSWORD
Login requests must be POSTs
HttpPost httpPost new HttpPostloginURL
HttpResponse response null
try
Execute the login POST request
response httpclientexecutehttpPost
catch ClientProtocolException cpException
Handle protocol exception
catch IOException ioException
Handle system IO exception
Setting Up Your Java Developer Environment
Verify the REST Environment RESTBased APIs
verify response is HTTP OK
final int statusCode
responsegetStatusLinegetStatusCode
if statusCode HttpStatusSCOK
SystemoutprintlnError authenticating to Forcecom
statusCode
Error is in EntityUtilstoStringresponsegetEntity
return
String getResult null
try
getResult EntityUtilstoStringresponsegetEntity
catch IOException ioException
Handle system IO exception
JSONObject jsonObject null
String loginAccessToken null
String loginInstanceUrl null
try
jsonObject JSONObject new
JSONTokenergetResultnextValue
loginAccessToken jsonObjectgetStringaccesstoken
loginInstanceUrl jsonObjectgetStringinstanceurl
catch JSONException jsonException
Handle JSON exception
SystemoutprintlnresponsegetStatusLine
SystemoutprintlnSuccessful login
Systemoutprintln instance URL loginInstanceUrl
Systemoutprintln access tokensession ID
loginAccessToken
release connection
httpPostreleaseConnection
The following example output shows a typical successful run of this code
HTTP OK
Successful login
instance URL httpsyourInstancesalesforcecom
access tokensession ID
DULSPxaXFirwBYCQXyvnKiCTiINnkKQJUUf
If the verification Java project runs and displays output that matches your organization your developer
environment is now set up and you can start developing Java applications that integrate with Salesforce