Skip to main content The Trailblazer Community will be unavailable from 2/1/2025 to 2/2/2025. Please plan your activities accordingly.
hi!

for a week now i am trying to connect to my Salseforce account just to retrive my data into my java aplaction and i cant seem to get it to work.

i read all over the internet and followoed every example i could find and nothing helped.

what i did so far is:

opened a developer account.

created an app with Oath2 authentication. (i do not have a callback server so i didn't know what to use).

what I'm trying to do is this:

connect to Salseforce.

retrieve all my leads created between 2 specific dates

I'm not even sure what will be the best API for that manner...

I would really appreciate some assistance.

thank you!

​Daniel
2 answers
  1. May 25, 2015, 12:00 PM
    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.

     

    import 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.");

    }

    }

    Use Partner.jar ,enterprise.jar and wsc.jar  while using above code in java.

    **Mark it as solved if it solves your question.

    Thanks,

    Naveen

    http://www.autorabit.com
Loading
0/9000