Using WSC to access Force.com from Java

Just published an article on Java integration - an alternative to using Apache Axis.

How do you integrate with Java – when you’re hitting the Force.com 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();
config.setUsername(USERNAME);
config.setPassword(PASSWORD);
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 Force.com Web Services Connector

Published
November 19, 2010
Topics:

Leave your comments...

Using WSC to access Force.com from Java