I'm doing an integration using Partner WSDL.

When I try to retrieve more than 15 Leads, it's return NullPointerException and I have 43 Leads. When I try to retieve all my Contacts, it's just return 23 and I have 43 Contacts.

Important, Contacts doesn't do any error, but Leads do. Someone can explain?


I created an Object Lead with all data a Lead in SF can have.

Lead lead = new Lead();
        Lead[] resultL = null;

        query = connection.query("SELECT" + " Id," + "FirstName," + " LastName," + " Company" + " FROM Lead"
                + " WHERE Company != NULL" + " ORDER BY CreatedDate" + " DESC");

        resultL = lead.queryLeads(connection, query);

The same thing for Contacts.

  • 2
    Most likely, it's a bug in your code. You certainly should be able to get up to 2,000 records per query()/queryMore() (depending on number of fields selected), and SOQL should not be returning a NullPointerException. Can you please add the relevant code you're using where you're getting the error? – sfdcfox Oct 10 '16 at 18:03
  • I'll update the question with a piece of code – Julio C. Boll Oct 10 '16 at 18:14
  • Can you show the line of code that corresponds to the NullPointerException? At a guess it would be somewhere inside your queryLeads method. Is it expecting a certain field that isn't being populated by the SOQL? – Daniel Ballinger Oct 10 '16 at 18:18
  • The code pass the lead.setId(sobj[j].getId()); then go to the lead.setFirstName(sobj[j].getField("FirstName").toString()); – Julio C. Boll Oct 10 '16 at 18:23


The Lead FirstName field is not required. As such, it will return as null via the API if it is not defined.

You will need to check if it is null before attempting to convert it to a string.

It is likely that you are only getting a subset of records back for the SOQL query as the API user that the session belongs to doesn't have access to all the records in question.

  • The Contact doesn't show NullPointerException – Julio C. Boll Oct 10 '16 at 18:32
  • But now I saw, for the Lead, just LastName and Company is required. – Julio C. Boll Oct 10 '16 at 18:34
  • sobj[j].getField("FirstName") will be returning null. The NullPointerException will be coming from calling toString() on that null. Try running the same SOQL query in the developer console and checking for Leads with no FirstName – Daniel Ballinger Oct 10 '16 at 18:34
  • @JulioC.Boll Yes, I got mixed up. I meant that it isn't a required field on Lead. I've corrected the answer. – Daniel Ballinger Oct 10 '16 at 18:35
  • 2
    @JulioC.Boll The user running the SOQL query via the API may not have access to all the Contacts in question. Get the ID of one of the records that aren't appearing in the SOQL results and try directly accessing that record. You will likely get a permission error. – Daniel Ballinger Oct 10 '16 at 18:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.