+ Start a Discussion

Invalid Query Locator Error



I have taken querysize = 2000. And when I am trieng to process more than 2000 records I am getting Invalid Query Locator Error.


But if I take querysize = 500 and when I process the application, Query Locator is working fine for 4 batches of 500 each. and then failing at 5th batch i.e, its unable to locate 2001st  record in any case.


Is there any restriction on querysize maximum value as 2000.  If any one knows the solution please post the solution in this forum.


Thanks and regards,


The maximum batch size is 2000, but there is no limit on the actual number of batches.  How long does it take you to process the 2000 records?  A queryLocator is not available indefinitely.
Ron HessRon Hess
are you checking for "done" , at that point the query locator is also invalid
To expand on DevAngel's points, you have to call queryMore at least every 15 minutes to keep the cursor alive, otherwise it gets invalidated, if you're doing a lot of processing on each row, and you're running in this you can use a smaller batch size so that you end up calling queryMore more often. The other thing you can run into, is that there's is a maximum of 5 open cursors per user at any one time, when you create a 6th cursor, the one with the oldest last used time is also inactivated. And as Ron mentioned, don't try to cursor off the end of the cursor, what's the size property on the queryResult say?

Thanks for your help. I implemented my logic so that the gap between query and querylocator calls to

the salesforce api is reduced to less than 15 minutes. Now it is working fine.

But as the process has to retrieve 40,000 records from AccountShare table.
I observed the from the execution of the process is that it is taking very long time for the subsequent records.
i.e, it took - 3 hours  -  for first 4500 records
for next    - 3 hours  -  it processed only 1500 records.
for next    - 3 hours  -  it processed only 500 records
If anyone know why it is taking so long time for the subsequent queries please intimate.
Awaiting for your reply.