Are you concerned about exposing the URL to an external system for integration and wish not to do so? Are you worried about sharing the Username / Password to connect to an external system and how to hide it? Then Named Credentials is the way to go and you are at right place to learn and know how to implement it!
Setup Named Credentials in Salesforce
Go to setup –> Named Credentials. Click New Named Credential button.
Enter the Label, Name and URL
Authentication Protocol as Password Authentication
Choose Identity Type as Named Principal and then choose Password Authentication for the protocol. Enter the username and password which you will pass.
When Authentication Protocol is OAuth 2.0
Named Credential can also be authenticated through OAuth method. Once we select OAuth 2.0 in Authentication Protocol. It shows us to Select Authentication Provider (configured in Salesforce). Before we can use this Named Credential to make the Callout, we have to authorize the details by Checking “Start Authentication flow on Save”. It will authenticate the details when we save the Named Credentials Definition. Put the scope as “refresh_token full”.
Once the Named Credentials are saved with “Authentication Status” Authenticated as <Username>, it is ready to use to make Callout. Remember Named Credentials won’t work if Status is Pending.
Use Named Credentials in code for callouts
I would love to automate the process to create the Named Credential record for a user. Can you set the flag ‘start authentication flow on save’ automatically using apex?
LikeLike