+ Start a Discussion
IX Salesforce AdminIX Salesforce Admin 

OnClick sforce.connection.query size limit


I am writing code for a button to update one field in all Opportunities in our system. The way I do is this:
var allIDs = sforce.connection.query("SELECT Id FROM Opportunity");
for (i = 0; i<parseInt(allIDs.size); i++){ var opportunityID = allIDs.records[i].Id; ...

the problem is that when I get allIDs.size, the size is 2593, however, as soon as the counter hits 2000 I get an error saying that it cant read ID from unidentified, also when I took the allIDs object and analyzed it in notepad++ I saw that it actually contains only 2000 records, but it shows size of 2593.
Later on I found out that there is a 2000 record limit on these queries. What are my alternatives?

Thank you!
karthikeyan perumalkarthikeyan perumal

SOQL-select record governer limit is 2000. so you have to user limit or OFFSET concept in your query is its more than 2000. 

it will be you use to avoid limit error . 

Seems you are using SOAP APIs, where by default the max records returned are 500, which could be uplifted to 2000. Best would be to use "queryMore" to load the records. Here is a post from salesforce docs with good code samples for the same:
 you have to use API call for this. 

kinldy consider below sample code: 
public void queryRecords() {
   QueryResult qResult = null;
   try {
      String soqlQuery = "SELECT FirstName, LastName FROM Contact";
      qResult = connection.query(soqlQuery);
      boolean done = false;
      if (qResult.getSize() > 0) {
         System.out.println("Logged-in user can see a total of "
            + qResult.getSize() + " contact records.");
         while (!done) {
            SObject[] records = qResult.getRecords();
            for (int i = 0; i < records.length; ++i) {
               Contact con = (Contact) records[i];
               String fName = con.getFirstName();
               String lName = con.getLastName();
               if (fName == null) {
                  System.out.println("Contact " + (i + 1) + ": " + lName);
               } else {
                  System.out.println("Contact " + (i + 1) + ": " + fName
                        + " " + lName);
            if (qResult.isDone()) {
               done = true;
            } else {
               qResult = connection.queryMore(qResult.getQueryLocator());
      } else {
         System.out.println("No records found.");
      System.out.println("\nQuery succesfully executed.");
   } catch (ConnectionException ce) {

read the linke carfully and try to change your code according to that. 

Hope this will helps you.