Created
November 28, 2013 05:26
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.spnotes.sfdc; | |
import com.sforce.soap.enterprise.Connector; | |
import com.sforce.soap.enterprise.EnterpriseConnection; | |
import com.sforce.soap.enterprise.QueryResult; | |
import com.sforce.soap.enterprise.sobject.Contact; | |
import com.sforce.ws.ConnectionException; | |
import com.sforce.ws.ConnectorConfig; | |
public class SFDCClient { | |
private static final String USERID = "replacewithuserid"; | |
private static final String PASSWORD = "replacewithpassword"; | |
private static final String SECURITYTOKEN = "replacewithsecuritytoken"; | |
public static void main(String[] args) { | |
try { | |
ConnectorConfig connectorConfig = new ConnectorConfig(); | |
connectorConfig.setUsername(USERID); | |
connectorConfig.setPassword(PASSWORD + SECURITYTOKEN); | |
connectorConfig.setPrettyPrintXml(true); | |
connectorConfig.setTraceMessage(true); | |
EnterpriseConnection connection = Connector | |
.newConnection(connectorConfig); | |
queryContacts(connection); | |
} catch (ConnectionException e) { | |
e.printStackTrace(); | |
} | |
} | |
private static void queryContacts(EnterpriseConnection connection) { | |
try { | |
QueryResult queryResults = connection | |
.query("SELECT Id, FirstName, LastName " + "FROM Contact "); | |
if (queryResults.getSize() > 0) { | |
for (int i = 0; i < queryResults.getRecords().length; i++) { | |
com.sforce.soap.enterprise.sobject.Contact c = (Contact) queryResults | |
.getRecords()[i]; | |
System.out.println(c.getFirstName() + c.getLastName() | |
+ c.getId()); | |
} | |
} | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment