Patrick Nijhuis Patrick Nijhuis - 5 months ago 27
ASP.NET (C#) Question

INVALID_SESSION_ID Error Salesforce Enterprise API

Currently I am developing an integration between local services and Salesforce using ASP.net and the Salesforce Enterprise API.

However I'm encountering a problem:


"INVALID_SESSION_ID: Invalid Session ID found in SessionHeader: Illegal Session. Session not found, missing session key: xxxxxx
This is expected, it can happen if the session has expired and swept away, or if the user logs out, or if its just someone trying to


hack in."


This error appears when I try to call the create function.

When I call the query function everything works smoothly.

The session time is set to 8 hours
in "session settings" the "Lock sessions to the IP address from which they originated" is unchecked.

Any idea where the problem comes from?

Answer Source

The error message is kind of misleading here. The session id in this case won't expire on timeout, I guess it's the endpoint url that needs to be set. (Not sure). Instead of trying to understand what's causing the issue, I solved it by catching the FaultException(code below) and invoking the login again. It worked like a charm.

catch (FaultException ex)
{
  if (ex.Code.Name == "INVALID_SESSION_ID")
   {                    
       Login();  
       //call your method again.                  
   };
}