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
shunshun 

How to keep session alive

Hi,

Is there a way to keep the session alive through the API by making some API calls within every two hour timeout period?  It seems that trying to keep the session alive using global describe calls or query calls  fails after a certain time, even though the session does last longer than the original 2 hour period.  

What is the maximum amount of time a session can be kept alive? 

What API calls should be used to keep the session alive?

Thanks,

Shun

 

DevAngelDevAngel

Hi Shun,

The session id is valid for 2 hours, after which you will need to login again.

shunshun

Hi Dave,

When working on the salesforce site itself, a prompt comes up that allows the user to continue the session - can we use the same kind of mechanism but through the API to keep the session alive? 

Also, I've tried keeping the session alive using query calls and the session seems to last longer than 2 hours.  Is there any combination of API calls that will keep the session alive indefinitely?

Sorry to basically ask you the same question, but I want to exhaust all possibilities of keeping the session alive before resorting to having the user have to relogin.

Thanks,

Shun

adamgadamg
One way to manage this issue is to wrap your api calls in a helper class that checks the status of the session, and auto-re-logins if the timeout has expired.  You can see an example of this (which is likely incomplete and still error prone) here:
 
 
In this example, I call isSessionValue before each call, and if not, just call init() again to relogin. 
VinnieBVinnieB

I'm just about to try and tackle this myself.  I was thinking of doing a quick call to get the system time using the existing binding object when opening up each servlet.   If that returns null, login again and update the binding object.  I don't expect us to have many users logged on at one time so this should be fine.

Any other suggestions or comments?  I'll look over the code example that was provided.  THANKS!!

adamgadamg
The code I provided is pretty terrible, but should provide the idea.  If you come up with enhancements let us know and we'll get them posted on sourceforge.
DevAngelDevAngel

Hi Shun,

Session ids are good for 2 hours from the time of issuance.  Notice there are not caveats or modifiers to that statement.  You don't have to have the user relogin.  If you cache the user credentials you can relogin behind the scenes.

shunshun

Thanks for the clarification.  We'll probably log the user in automatically behind the scenes.

Shun

java devjava dev

Hi I want the code which you provided in the link on sourceforge.

 

I am not able access the code through the link.

Can you send me the code to tumusudheer@yahoo.co.in

thank you,

Sudheer.