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
MilanMilan 

Illegal Session error

Hello,

Recently we have seen a number of errors such as the following in our logs:

Invalid Session ID found in SessionHeader: Illegal Session

Our app integrates with SalesForce AppExchange. From what I've read, this error may mean that the user's SalesForce session has expired, although they may still be able to interact with our application in the AppEx frameset. This seems to make some sense in that the point in the user's experience where we are seeing this error is during checkout, which means that it may be possible for them to have been using the app long enough for their Sales Force session to expire.

Does this error really indicate that the user's SalesForce session has expired and, if so, is there something I can do through integration to help keep it alive or re-initialize it? How do other people deal with this issue?
Best Answer chosen by Admin (Salesforce Developers) 
werewolfwerewolf
If this is an Scontrol and you're within an Iframe that has been redirected, sometimes you have to manually set the session ID from the cookie because it doesn't pick it up automatically.  I can't remember the exact syntax because I can't find the org in which I did this, but it's something like:

Code:
sforce.sessionId = getCookie('sid');

It becomes reasonably obvious when you use Firebug to debug just before your login call that the session ID variable is unset, and so you just have to set it before you do anything.

If this is _not_ an Scontrol, then make sure you're not losing your sessionId somewhere in the process.  That would also cause this problem.  Also, as you surmised, if the user is legitimately timed out then you'll get this issue, in which case the only fix is to get a new sessionId by re-logging in.

All Answers

werewolfwerewolf
If this is an Scontrol and you're within an Iframe that has been redirected, sometimes you have to manually set the session ID from the cookie because it doesn't pick it up automatically.  I can't remember the exact syntax because I can't find the org in which I did this, but it's something like:

Code:
sforce.sessionId = getCookie('sid');

It becomes reasonably obvious when you use Firebug to debug just before your login call that the session ID variable is unset, and so you just have to set it before you do anything.

If this is _not_ an Scontrol, then make sure you're not losing your sessionId somewhere in the process.  That would also cause this problem.  Also, as you surmised, if the user is legitimately timed out then you'll get this issue, in which case the only fix is to get a new sessionId by re-logging in.
This was selected as the best answer
PFangPFang
You are the main man! I can kiss you for this, spent hours on trying to pull the session ID from Salesforce and yours is the only one that worked!
Bhawani SharmaBhawani Sharma
You are superb. I tried almost each and every option and after that this worked for me.