How long will a jsForce connection last?


const connection:Connection = new jsforce.Connection({
    loginUrl: process.env.SFDC_LOGIN_SERVER || 'login-url'

// how long will this connection live before it needs to be logged in again?

I have searched the documentation, but I have not found anything about how to configure a connection lifespan, nor have I found an answer for how long the connection will live until a login is required again.


1 Answer 1


The session is configured in Salesforce, between 15 minutes and 24 hours. Your app gets an "expiryDate" or some such when you log in. You can reliably use that token until it expires, unless it is logged out early. If you use the token in the second-half of its life span, it will automatically renew, so it can last potentially forever. The recommended pattern for using the Salesforce API is to just try-catch every API call, and if you get a 401 error, just log in again and retry the API call.

  • 1
    403 error or 401 error? I see developer.salesforce.com/docs/atlas.en-us.api_rest.meta/… 401: "The session ID or OAuth token used has expired or is invalid. The response body contains the message and errorCode." vs 403: "The request has been refused. Verify that the logged-in user has appropriate permissions. If the error code is REQUEST_LIMIT_EXCEEDED, you’ve exceeded API request limits in your org."
    – Peter W
    Apr 11 at 23:17
  • 1
    @PeterW I probably just wrote this from memory without checking the docs. Thanks for the catch! I've edited in the correct value.
    – sfdcfox
    Apr 12 at 17:40

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