[SalesForce] When should I use SoapBindingStub v/s Connector

I was searching for salesforce apis and got two code to login to salesforce using partner wsdl.

This example uses SoapBindingStub to login to salesforce. Sample code

import com.sforce.soap.partner.SoapBindingStub;
import com.sforce.soap.partner.LoginResult;

//Code
SoapBindingStub binding = (SoapBindingStub) new SforceServiceLocator().getSoap();
loginResult = binding.login("username", "password");
System.out.println("\nThe session id is: " + loginResult.getSessionId());

And this example uses Connector to login to salesforce. Sample code

import com.sforce.soap.partner.Connector;
import com.sforce.ws.ConnectorConfig;
import com.sforce.soap.partner.PartnerConnection;

//Code
ConnectorConfig config = new ConnectorConfig();
config.setUsername("username");
config.setPassword("password");
PartnerConnection connection = Connector.newConnection(config);
System.out.println("\nThe session id is: " + config.getSessionId());

My question

  1. When should I use one of them?
  2. Both approaches are using some different jar or wsdl?

Thanks.

Best Answer

It would appear that the first referenced example using the generated SoapBindingStub is a basic import of the Partner API. Using an Ant build script, the Partner WSDL and Apache Axis you generate proxy classes that can be used to invoke the API.

The second example appears to create a richer set of generated Java classes for accessing the SOAP web services and Bulk API. I can see classes such as a SessionRenewer and Base64 that indicate extended features and support that you wouldn't get with Apache Axis.

I'd say use the first approach if you just want basic access to the Partner API from java. The second is an option if you need access to more than just the Partner API and extended features such as a session that gets renewed on expiry.

Related Topic