Named Credentials – Setup | Apex Callout

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!


Check how to use Named Credentials in Code for callouts


Setup Named Credentials in Salesforce

Go to setup –> Named Credentials.  Click New Named Credential button.

named credentials code salesforce sfdcfanboy

Enter the Label, Name and URL

new named credential salesforce sfdcfanboy

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.

edit named credential salesforce sfdcfanboy

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”.

named credential salesforce oauth 2.0 sfdcfanboy

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


Check how to use Named Credentials in Code for callouts


 

 

Advertisements

One Reply to “Named Credentials – Setup | Apex Callout”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s