Named Credentials using password authentication

authenticationnamedcredentialspasswords

I need to call the same org using named credential password authentication,. Can anyone explain if i need to pass a api for the password where could I get that api for same salesforce org?

Best Answer

As you are accessing the API from the same Salesforce org, you can use SessionId, which should be the recommended approach. However, if you still wish to use Connected App and named credentials please follow the below step:

  1. Create a Connected App with OAuth Scope of "Full Access" and "refresh token".
  2. Create an Auth Provider with default scope as refresh and full.
  3. Update the connected app with callback URL from auth provider.
  4. Create a Named Credential with the same scope as above and Authentication protocol as oAuth 2.0. Please tick "Start Authentication Flow on Save" as true. This will redirect you to authenticate the Salesforce login using oAuth webserver flow.
  5. Use the named credentials in your callout.