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
JavaJava 

Getting INVALID_SESSION_ID from query method

I am running a java application after every 1 hour which queries some data from salesforce and do some further processing. But when query method is called it gives me the following problem. This problem is coming most of the time but not always.

I receive the following exception:

AxisFault
 faultCode: {http://schemas.xmlsoap.org/soap/envelope/}Server
 faultSubcode:
 faultString: INVALID_SESSION_ID: Invalid Session ID found in SessionHeader
 faultActor:
 faultNode:
 faultDetail:
 {urn:fault.partner.soap.sforce.com}fault:
     <sf:exceptionCode>INVALID_SESSION_ID</sf:exceptionCode>
     <sf:exceptionMessage>Invalid Session ID found in SessionHeader</sf:exceptionMessage>
   

INVALID_SESSION_ID: Invalid Session ID found in SessionHeader
 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:125)
 at org.apache.axis.encoding.ser.BeanDeserializer.<init>(BeanDeserializer.java:111)
 at com.sforce.soap.partner.fault.UnexpectedErrorFault.getDeserializer(UnexpectedErrorFault.java:84)
 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:176)
 at org.apache.axis.encoding.ser.BaseDeserializerFactory.getDeserializerAs(BaseDeserializerFactory.java:117)
 at org.apache.axis.encoding.DeserializationContextImpl.getDeserializer(DeserializationContextImpl.java:466)
 at org.apache.axis.encoding.DeserializationContextImpl.getDeserializerForType(DeserializationContextImpl.java:481)
 at org.apache.axis.message.SOAPFaultDetailsBuilder.onStartChild(SOAPFaultDetailsBuilder.java:172)
 at org.apache.axis.encoding.DeserializationContextImpl.startElement(DeserializationContextImpl.java:963)
 at org.apache.xerces.parsers.AbstractSAXParser.startElement(Unknown Source)
 at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown Source)
 at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
 at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
 at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
 at org.apache.xerces.parsers.DTDConfiguration.parse(Unknown Source)
 at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
 at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
 at javax.xml.parsers.SAXParser.parse(Unknown Source)
 at org.apache.axis.encoding.DeserializationContextImpl.parse(DeserializationContextImpl.java:242)
 at org.apache.axis.SOAPPart.getAsSOAPEnvelope(SOAPPart.java:538)
 at org.apache.axis.Message.getSOAPEnvelope(Message.java:376)
 at org.apache.axis.client.Call.invokeEngine(Call.java:2583)
 at org.apache.axis.client.Call.invoke(Call.java:2553)
 at org.apache.axis.client.Call.invoke(Call.java:2248)
 at org.apache.axis.client.Call.invoke(Call.java:2171)
 at org.apache.axis.client.Call.invoke(Call.java:1691)
 at com.sforce.soap.partner.SoapBindingStub.query(SoapBindingStub.java:979)
 at com.salesforce.samples.NewSchedulerForAstaro.getAllDataFromCampaignMember(NewSchedulerForAstaro.java:438)
 at com.salesforce.samples.executeSchedulerForAstaro.getData(executeSchedulerForAstaro.java:126)
 at com.salesforce.samples.executeSchedulerForAstaro$RemindTask.run(executeSchedulerForAstaro.java:105)
 at java.util.TimerThread.mainLoop(Unknown Source)
 at java.util.TimerThread.run(Unknown Source)

Current it is called when i am calling the query method of salesforce.

Any help would be highly appreciated as i want to get rid of this problem as early as possible.

Thanks,

 

 

JasonRogersJasonRogers
Your session has probably timed out. I don't recall what the default timeout is, but you can set it explicitly on the Soap object (after casting it to a Stub).

eg.
((Stub) soap).setTimeout();
DevAngelDevAngel

I think that this is a different timeout.  The timeout on the stub is the timeout to wait for a response from the service.  The exception is coming from the service, so that timeout is not being triggered.  The response indicates that a call was successfully made and a response successfully received.  The issue I think is that the sessionId or authentication token that is recognized by salesforce.com has gone stale.  The sessionId for salesforce.com expires 2 hours after it was issued.  This behavior is divergent from the way the application works.  The application has a session expiration based on last activity and can be set to 30, 60, 90 or 120 minutes via the setup area of the application. 

A developer should expect the sessionId to remain valid for 2 hours after the Id is obtained via the login call.  This is not what the original post indicates.  I don't have an answer for why the poster's Id is only lasting for one hour (I suspect that the id is actually older than he/she thinks).  In any case, for a long-running ETL type process, you should always handle the possibility that the session will expire and obtain a new session id via the login call.

FYI - we are going to revamp the session time-out behavior to reflect the way the app works and to ease the developer's burden by shifting to a time-out that is based on last activity.  This will likely be near the end of the calendar year.

JavaJava

I understood that this problem could be due to seesion out in salesforce after 2 hours. Is there any API call such as logout that can log me out of salesforce as and when required.

zakzak
There's no call to specifically logout, but you can call login at any time to get a new sessionId with a new 2 hour window.
preeteepreetee

Hi,

I am looking at the same problem. Please let me know if this approach is correct and will work.

If I check for INVALID_SESSION_ID and then login again, will it start the process from where it had left ? Meaning, suppose I was making query calls when the session timedout, will my previous query results be available  ? Also, will the queries be obtained from where it had stopped ? Say, session timedout for query result 205, will logging in again get me result 206 ?

Please reply at the earliest.

Thanks,

Preetee

SuperfellSuperfell
The cursor for QueryMore is associated to your userId, not your sessionId, so if you login again and get a new sessionId, your query cursor is not affected.