So, suppose I managed to get refresh_token, what happens now:

  1. Should I perform a new access token request every time I connect (so I send the refresh token before connecting, every time)
  2. Try if the current access token I own still works, otherwise perform the refresh access token request

Which one should I aim for?

2 Answers 2


Generally I'd go with the second, there's no need to refresh if the current one works. Current code bases I have attempt to use the access token and if it fails then it grabs a new one via the refresh token. Just saves doing an extra request every single time and therefore has the potential to be a little quicker for the end user.

  • Mhh probably I'll use this version because I'm definitely not sure how to find out the session expiry time. It also saves another if branch Commented Nov 28, 2014 at 2:11

Depending on the use case, if you have an application and if you have the ability to store the timestamp of your last API callout, then you can check the time difference between now and your last call against the session expiry time in SF. If the time difference < session expiry time, use access token followed by a refresh token if it fails. In case where the time difference is greater and you know that the access token has expired, then go straight with the refresh token. This gives you, to some extent, the ability to save a few API calls and round-trips to the server.

You must log in to answer this question.

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