Named Credentials – Code | Apex Callout

Are you concerned about exposing the URL to external system for integration and wish not to do so? Are you worried about sharing the Username / Password to connect with 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!

Definition

A named credential specifies the URL of a callout endpoint and its required authentication parameters in one definition. To simplify the setup of authenticated callouts, specify a named credential as the callout endpoint.

If you instead specify a URL as the callout endpoint, you must register that URL in your org’s remote site settings and handle the authentication yourself.

For example, for an Apex callout, your code would need to handle authentication, which can be less secure and especially complicated for OAuth implementations.

Difference Between Authentication Provider & Named Credentials

Developers usually gets confused between Authentication Provider & Named Credentials.  The difference is Authentication Provider is used for authenticating external application using OAuth where as Named Credentials is used to hide URL information from being exposed rather gives a short friendly name to use instead.

How to setup Named Credentials in Salesforce

Check how to Setup Named Credentials in Salesforce.  I’ve highlighted with Screenshots as well.


Setup Named Credentials in Salesforce


 How Named Credential Works?

– Direct way to make Callout in Apex

– Callout using Named Credentials

Syntax to use Named Credentials. In the following code snippet, we’re using SalesforceNC instead of ENDPOINT.


Setup Named Credentials in Salesforce


 

Advertisements

2 Replies to “Named Credentials – Code | 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 )

Connecting to %s