I have to integrate Salesforce with an external app using OAuth2.0. I create Auth. Provider and Named Credential, authenticated successfully too.

But I'm getting one issue with Named Credential : The authentication provider didn't provide a refresh token. If the access token expires, your org won't be able to access this named credential.

With this issue I don't think the access token will be refreshed automatically, right?

What options do I have to get the access token once it expires?

I tried, getAccessToken(authProviderId, providerName) but it keeps returning null. String accessToken = Auth.AuthToken.getAccessToken('0SO5j000000sgZNGAY', 'Open ID Connect');

  • You'd have to reinitialize the auth provider underneath NC to restart the token acquisition sequence without the refresh token. One option: when token expires, manually delete NC and recreate it. (Do not delete or touch Auth Provider). There might be a less intrusive way to kick off a reinit...caveat emptor.
    – identigral
    Dec 6, 2021 at 19:12
  • @identigral - The only downside is that currently Access_Token expires in 1 hour. But let's say if I get that extended to a week/month. Is it a good solution to initiate Authentication flow of Named Credential ever week/month in order to keep things running? Or should I build a custom apex code to fetch the access token itself? Dec 7, 2021 at 5:42
  • Custom code is better.
    – identigral
    Dec 7, 2021 at 5:53

1 Answer 1


Got this resolved. Hope this helps someone.

The application exposing the REST API didn't had offline_access scope configured at their scope.

Once this is done, we need add the offline_access scope back to our NC and then Salesforce will be able to refresh the access token on its own.

  • Does this mean that named creds do not refresh tokens if there's nothing specified in the scope parameter ? Aug 26, 2022 at 14:08

You must log in to answer this question.

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