Hi Daniel, If you want to connect to only your salesforce org use enterprise connection.If you want to connect to any salesforce org you can use partner connection.Below is the sample code in java which retrieves Lead info from Salesforce using PartnerConnection.
Use Partner.jar ,enterprise.jar and wsc.jar while using above code in java.**Mark it as solved if it solves your question.Thanks,Naveenhttp://www.autorabit.comimport com.sforce.soap.partner.PartnerConnection;
import com.sforce.soap.partner.QueryResult;
import com.sforce.soap.partner.sobject.*;
import com.sforce.soap.partner.*;
import com.sforce.ws.ConnectorConfig;
import com.sforce.ws.ConnectionException;
import com.sforce.soap.partner.Error;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.util.*;
public class PartnerCon2 {
PartnerConnection partnerConnection = null;
public static void main(String[] args) {
PartnerCon2 samples = new PartnerCon2();
if (samples.login())
samples.querySample2();
}
private boolean login() {
boolean success = false;
try {
ConnectorConfig config = new ConnectorConfig();
config.setUsername("naveen.sforce@gmail.com");
config.setPassword("Techrains@12345L1vRecUnTMw2LKabdigpr89o");
config.setAuthEndpoint("https://login.salesforce.com/services/Soap/u/33.0");
config.setTraceFile("traceLogs.txt");
config.setTraceMessage(true);
config.setPrettyPrintXml(true);
partnerConnection = new PartnerConnection(config);
success = true;
} catch (ConnectionException ce) {
ce.printStackTrace();
} catch (FileNotFoundException fnfe) {
fnfe.printStackTrace();
}
return success;
}
public void querySample2() {
try {
partnerConnection.setQueryOptions(250);
String soqlQuery = "SELECT FirstName, LastName FROM Lead";
QueryResult qr = partnerConnection.query(soqlQuery);
for (SObject s : qr.getRecords()) {
System.out.println("Lead Info :" + s.getField("FirstName")
+ " " + s.getField("LastName"));
}
} catch (ConnectionException ce) {
ce.printStackTrace();
}
System.out.println("\nQuery execution completed.");
}
}
2 answers