3

I'm using the login() API method to retrieve a session id from SalesForce that I then use in a number of following requests. For each set of requests I check if the token is older than 15 minutes (I have a 30 minute timeout).

Question 1: Sometimes when calling login() I receive an identical session id as I did in my previous call to login()? How is that possible, won't a call to login() always produce a fresh 30 minute valid token? Please explain this as behavior as detailed as possible, and maybe I'm totally off here?

Question 2: If I request a token by login() and I receive a token that is about to timeout (assuming I don't always get a new one, as asked in q1 above) I can end up in a situation where I timeout in the middle of my set of request. So is it then best practice to always wrap all calls and catch timeout exception and the request a new one?

1 Answer 1

6

Sessions expire automatically after a predetermined length of inactivity, which can be configured in Salesforce from Setup by clicking Security Controls. The default is 120 minutes (two hours). If you make an API call, the inactivity timer is reset to zero.

So when you try and login and your session is still valid (you were last active within 30 minutes in your case) it's not surprising that you get the same session ID back.

Each time you call into Salesforce your session will be valid for 30 minutes from that point.

Hope that helps.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .