+ Start a Discussion

INVALID_QUERY_LOCATOR: invalid query locator

While running a fairly long series of queryMore() calls, after about 17 minutes of activity (in 2000 record chunks), I received the "INVALID_QUERY_LOCATOR: invalid query locator" error.

I was using logic borrowed from the sample code illustrating the proper use of query() and queryMore(), and this code has previously been tested to run without errors.

Is it possible that the query locator/cursor expires after a period of time, or for some other reason became invalid?

Message Edited by HaroldH on 03-15-2005 02:58 PM

I most cases I found I'll get this error when I'm trying to do alot of procesing while getting those records... That is to say issuing other queries/updates inside the loop that is iterating through the records.

For large recordsets what I do is allocate a local array to hold those records, iterate through all the returned records storing them in the local array, and then processing them.

Hope that helps...
You can have a max of 5 querylocators open. If your user had more than 5 open, it's possible the one you are working on got cleaned up. Or, if you wait more than 10 minutes before calling queryMore, it will also be removed from the system.

Thanks for clarifying the 10 minute inactivity timeout of a queryLocator.

Seems that using a smaller batch size (ie, less than the maximum of 2000) may help in our case, where processing those 2000 records is taking a fair bit of time.


Yes, or as daroz suggests, bring all the data into your program (if you have that much memory to spare)
Hi all,
i'm experimenting the same problem in this days.
We have an utility mathod that consume all the server records(batch size 2000) of a QueryResult and store them in a local array and then return the local array to calling methods for local complex operations.
The calling method uses more then 5 times this utility method(during his lifeline) but I can understand why we get "InvalidQueryLocator" exception.

Does QueryLocator server instance die when QueryResult comes Null?

Does QueryLocator ql=queryresult.getQueryLocator() get a new copy of the same remote QueryLocator instance?

Can I remotely manipulate my querylocator instance during a session(for example how many QueryLocator instance I hold in a specific moment)?

The ten minutes expire time concerne total query time or time between two different "QueryMore" invocations?

Does something changes in the summer edition about query expire time. Our code seems to work on the previous WSDL?

thanks in advance

--->>>>>>>This is the method code:
public static SObject[] queryObjects(QueryResult qr, SoapBindingStub sbs)throws UnexpectedErrorFault, InvalidQueryLocatorFault, RemoteException{
SObject[] selected=null;
MyLogger.info(LOGGING_CLASS,"record restituiti: "+qr.getRecords().length);
MyLogger.info(LOGGING_CLASS,"record restituiti: 0");
selected = qr.getRecords();
Vector vso=new Vector();
while (qr.getRecords() != null) {
MyLogger.info(LOGGING_CLASS,"record restituiti: "+qr.getRecords().length);
vso.addAll(new Vector(Arrays.asList(qr.getRecords())));
QueryLocator ql=qr.getQueryLocator();
if(ql != null)
qr = sbs.queryMore(ql);
selected=new SObject[vso.size()];

return selected;