Using the Web Services Connector to access the API

In this post we will be creating a client application that can communicate with and alter the data in your org.  This would be the building blocks for a custom Java on-premise app.  We are using the WSC open source project for connection to  This is a web service client stack that makes it easier to use the API.  Find it here:

Here is my configuration:

  • I am using Eclipse (Juno) on a Mac OS X (10.8.2).’
  • Java 1.6.0_37 (JDK 1.6 is required)


  • Create a project in eclipse.  I named mine: sfdc-wsc-enterprise
  • Log into your org and download the necessary WSDL file (Setup –> Develop –> API –> Enterprise WSDL)
  • Save the WSDL to the top level folder of your eclipse project: enterprise.wsdl
  • Download the WSC Jar.  I downloaded wsc_22.jar and placed it the top level folder of my project.
  • Issued the following command from the command line:
~/dev/sfdc-wsc-enterprise cloudguy$ java -classpath wsc-22.jar enterprise.wsdl enterprise.jar
  • This generates the enterprise.jar file and places it in your directory path.
  • Add the JARs to your project (Project –> Properties –> Java Build Bath –> Libraries)
  • Add a new package to your project: com.cloudpremise.samples.sfdcWscEnterprise
  • Add a new class, SimpleIntegration.class to the new project:
package com.cloudpremise.samples.sfdcWscEnterprise;
import com.sforce.soap.enterprise.Connector;
import com.sforce.soap.enterprise.EnterpriseConnection;
import com.sforce.soap.enterprise.SaveResult;
import com.sforce.soap.enterprise.sobject.Account;
public class SimpleIntegration {
static EnterpriseConnection connection;
  public static void main(String[] args) {
    ConnectorConfig conn = new ConnectorConfig();
    conn.setUsername("<your user id here>");
    conn.setPassword("<your pw + security token here>");
    try {
      connection = Connector.newConnection(conn);
      //create an account
      Account[] newAccounts = new Account[1];
      Account a = new Account();
      a.setName("New Account Name");
      SaveResult[] saveResults = connection.create(newAccounts);
      if (saveResults[0].isSuccess()) {
      System.out.println("Created Account with ID: " + saveResults[0].getId());
    } catch (ConnectionException e1) {

That’s it!  Now you can make calls directly into your org from Java.  You can use the WSC connector to simplify a lot of the work for connecting into your org.  Notice no use of Axis, Jax-WS, etc.  Just a simple download of the WSC and you will be off and running in no time.


new account screen shot

2 Comments on “Using the Web Services Connector to access the API”

  1. Hi,
    I am trying to execute your sample program to integrate java and sfdc, I am facing couple of issues like 1) where exactly i need to place the enterprise.wsdl and wsc-23-min.jar file to generate the enterprise.jar.
    Kindly let know how to resolve the issue.

    • I created a new project for this and placed the enterprise WSDL and the WSC jar in the top level folder of my project. If the blog side bar is blocking the command line here it is again for your reference:
      ~/dev/sfdc-wsc-enterprise cloudguy$ java -classpath wsc-22.jar enterprise.wsdl enterprise.jar

      You can see the sfdc-wsc-enterprise is my top level folder where both the wsc jar and the enterprise.wsdl have been added.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: