We have created a standard callout class to establish a connect between Salesforce to SMIT system, and then we have provided our Salesforce credentials (like clientid, client secret etc). They established a connection between Salesforce and there system.

After establishment of connection they are receiving below error,

        "message": "Session expired or invalid",
        "errorCode": "INVALID_SESSION_ID"
Could you please help me. Did I miss anything in the class or do I need to enable any connection from Salesforce end?
  • Welcome to SFSE! Please take a moment to read How to Ask and take the tour. Including a Minimal, Reproducible Example would be helpful. Your code snippet does not show the call to Salesforce nor does your question contain details of other steps necessary to reproduce the issue.
    – identigral
    Commented Sep 1, 2022 at 16:11

1 Answer 1


We just had the same error. After successful authentication using the SalesForce Rest API in sandbox we immediately got an errorCode "INVALID_SESSION_ID" when trying a GET request on a custom endpoint.

It seems like salesforce v56 has updated the instance url. Make sure that you are using the instance_url that is being returned after successful authentication.

In v55 our authentication flow returned an instance_url like this:


In v56 the instance_url returned was different, with an added 'sandbox':


https://ourdomain--sbox3.my.salesforce.com/services/apexrest/v1/endpoint/ returns the invalid session error. https://ourdomain--sbox3.sandbox.my.salesforce.com/apexrest/v1/endpoint successfully returns data as expected.

Since our salesforce production environment (as of 19 Sept 2022) is still on v55, we don't know if this update will affect production. But we are watching it and our release date to be safe.

  • 2
    the URL change is a function of Enhanced Domains being enforced for sandboxes as of Winter 23 (V56). See Setup | Release Updates
    – cropredy
    Commented Sep 20, 2022 at 1:33

You must log in to answer this question.

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