Using WSC to access from Java | Salesforce Developers Blog

How do you integrate with Java – when you’re hitting the SOAP WSDL endpoints?  I use WSC.  Before that, I used to use Apache’s WSDL2Java.

WSC is pretty cool – run it against your enterprise WSDL (say – it works with partner / metadata too), and you get a little JAR that you can include, which lets you write really simple, straightforward code.  Like this:

ConnectorConfig config = new ConnectorConfig();
connection = Connector.newConnection(config);
QueryResult queryResults = connection.query("SELECT Id, FirstName, LastName, Account.Name " +
"FROM Contact WHERE AccountId != NULL ORDER BY CreatedDate DESC LIMIT 5");
if (queryResults.getSize() > 0) {
for (int i=0;i < queryResults.getRecords().length;i++) {
// cast the SObject to a strongly typed Contact
Contact c = (Contact)queryResults.getRecords()[i];
System.out.println("Id: " + c.getId() + " - Name: "+c.getFirstName()+" "+
c.getLastName()+" - Account: "+c.getAccount().getName());

Tell me that’s not pretty!  No pain, plenty of gain.

To learn more, check out the article we’ve just published: Introduction to the Web Services Connector

Stay up to date with the latest news from the Salesforce Developers Blog