2

I'm using Named Credentials to support a Scheduled Apex job that needs to call into the Salesforce REST API. The Named Credential is of type Named Principal, using Oauth, and it works just fine.

Here's my question: is there any way for my Apex code to determine whether this credential currently has a valid authentication status and, if not, prompt the user to authenticate? I'm wondering about the deployment process for this application to my production instance - do I need to manually authorize the named credential as part of my deployment process, or can I account for this in code?

2 Answers 2

1

Since your environment changed when you move to production, you need to do a manual step to authorize the user used for the integration. With Named credential, after you deploy it , use the Start Authentication Flow on Save option to authorize the user. enter image description here

As for Oauth you would be using access token for the integration. Reading this might be helpful - OAuth Access Token Expiration

0

You can handle this by an error handling in the catch block. Once, we marked this as a post-deployment step to authenticate the named credential whose identity type is 'named principal' with a user having the admin profile.

2
  • I don't understand how a catch block can be a post-deployment step. (What Exception would you catch anyway?) Feb 9 at 14:21
  • I mean, eventually, it is a manual step. Putting it in a catch block is a separate topic. You can notify the user by creating a toast message or an error log record on the UI.
    – Kenan Ce
    Feb 12 at 8:46

You must log in to answer this question.

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