function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
DayaDaya 

INVALID_QUERY_LOCATOR on retrieving records from Lead Object

I was able to retrieve all records from Lead object earlier(with 80k) . But now, my lead size grown upto 500k records. I'm getting the following error. Your help is very much a apprectiated
 
My code snippet:
 
....
....
  try
  {
   String sql="SELECT "+<<all_columns_from_lead_object>>+" FROM Lead"
   QueryResult queryResult = binding.bind().query(sql);
   while (true) {
    SObject[] sObjs = queryResult.getRecords();
    if (sObjs==null || sObjs.length==0) {
     break;
    }
    //Begin: retrieving sObjs and storing into csvfile && our biz logic here..
    ...
    ...
    ...
    //End: retrieving sObjs and storing into csvfile && our biz logic here..
    if (queryResult.isDone()) {
     break;
    } else {
     queryResult = binding.bind().queryMore(queryResult.getQueryLocator());
    }
   }
  }catch (Exception e) {
   the_log.error(e);
  }
...
...
 
Exception:
ERROR 2007-06-14 11:27:06,190 (SFCampaignMemberBO.java:924) - Unable to execute doSelect
AxisFault
 faultCode: {urn:fault.partner.soap.sforce.com}INVALID_QUERY_LOCATOR
 faultSubcode:
 faultString: INVALID_QUERY_LOCATOR: invalid query locator
 faultActor:
 faultNode:
 faultDetail:
 {urn:fault.partner.soap.sforce.com}fault:<ns1:exceptionCode>INVALID_QUERY_LOCATOR</ns1:exceptionCode><ns1:exceptionMessage>invalid query locator</ns1:exceptionMessage>
INVALID_QUERY_LOCATOR: invalid query locator
 at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
 at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
 at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
 at java.lang.reflect.Constructor.newInstance(Unknown Source)
 at java.lang.Class.newInstance0(Unknown Source)
 at java.lang.Class.newInstance(Unknown Source)
 at org.apache.axis.encoding.ser.BeanDeserializer.<init>(BeanDeserializer.java:104)
 at org.apache.axis.encoding.ser.BeanDeserializer.<init>(BeanDeserializer.java:90)
 at com.sforce.soap.partner.fault.InvalidQueryLocatorFault.getDeserializer(InvalidQueryLocatorFault.java:85)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
 at java.lang.reflect.Method.invoke(Unknown Source)
 at org.apache.axis.encoding.ser.BaseDeserializerFactory.getSpecialized(BaseDeserializerFactory.java:154)
 at org.apache.axis.encoding.ser.BaseDeserializerFactory.getDeserializerAs(BaseDeserializerFactory.java:84)
 at org.apache.axis.encoding.DeserializationContext.getDeserializer(DeserializationContext.java:464)
 at org.apache.axis.encoding.DeserializationContext.getDeserializerForType(DeserializationContext.java:547)
 at org.apache.axis.message.SOAPFaultDetailsBuilder.onStartChild(SOAPFaultDetailsBuilder.java:157)
 at org.apache.axis.encoding.DeserializationContext.startElement(DeserializationContext.java:1035)
 at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(Unknown Source)
 at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown Source)
 at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
 at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
 at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
 at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
 at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source)
 at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(Unknown Source)
 at javax.xml.parsers.SAXParser.parse(Unknown Source)
 at org.apache.axis.encoding.DeserializationContext.parse(DeserializationContext.java:227)
 at org.apache.axis.SOAPPart.getAsSOAPEnvelope(SOAPPart.java:696)
 at org.apache.axis.Message.getSOAPEnvelope(Message.java:435)
 at org.apache.axis.handlers.soap.MustUnderstandChecker.invoke(MustUnderstandChecker.java:62)
 at org.apache.axis.client.AxisClient.invoke(AxisClient.java:206)
 at org.apache.axis.client.Call.invokeEngine(Call.java:2812)
 at org.apache.axis.client.Call.invoke(Call.java:2795)
 at org.apache.axis.client.Call.invoke(Call.java:2461)
 at org.apache.axis.client.Call.invoke(Call.java:2384)
 at org.apache.axis.client.Call.invoke(Call.java:1830)
 at com.sforce.soap.partner.SoapBindingStub.queryMore(SoapBindingStub.java:1743)
 at responsys.sf2ri.model.bo.SFCampaignMemberBO.selectSfDataAsCSVFile(SFCampaignMemberBO.java:915)
 at responsys.sf2ri.model.bo.RIEtlBO.mergeDataIntoSfLeadOrContactTableForAutomationJob(RIEtlBO.java:2528)
 at responsys.sf2ri.model.bo.Sf2RiAutomationWorker.uploadSfContactsNLeadsDataForAutomationJob(Sf2RiAutomationWorker.java:2137)
 at responsys.sf2ri.model.bo.Sf2RiAutomationWorker.transferAllLeadsNContacts(Sf2RiAutomationWorker.java:238)
 at responsys.sf2ri.model.bo.Sf2RiAutomationWorker.run(Sf2RiAutomationWorker.java:2459)
 at java.lang.Thread.run(Unknown Source)
 
dhruvadhruva
Do all the retrieving before you do any logic.  I've noticed before that the queryLocator has a short lifetime, and
sometimes it can be shorter than your logic time.
SuperfellSuperfell
You have to use the queryLocator at least one every 15 minutes to keep it active.