I am trying to build Salesforce to Salesforce integration using Named Credentials.

Followed steps from below blog.


  • Created Connected App in destination org
  • Created Authorization Provider in source org
  • Defined Named Credential in source org.

    HttpRequest feedRequest = new HttpRequest();
    Http http = new Http();
    HTTPResponse feedResponse = http.send(feedRequest);

When I ran above code in Source Org (anonymous window) then am getting below error

Session expired or invalid


3 Answers 3


when I checked Generate Authorization Header check box on Named Credential then error went off.

enter image description here

  • hey, where is the above option in salesforce dashboard? Jan 3, 2018 at 14:05

Named credentials works fine. It looks like request is reaching the host and you are getting the response as session expired. In Named Credentials you can set basic authentication or oauth please check which one of them are being used.

  • I have specified OAuth 2.0 in Named Credentials
    – sfdc
    Dec 15, 2015 at 16:36

Yes... Finally... I am able to get the response from other org...

Make sure that while creating named credentials.. you should give URI as "https://xxxxxxxxxx-dev-ed.my.salesforce.com"

I gave "xxxxxxxx-dev-ed.lightning.force.com" >>> Throwed the error...

so correct URI is "https://xxxxxxxxxx-dev-ed.my.salesforce.com".

You must log in to answer this question.

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