Named credentials for integration callouts
Key Takeaway
Set your Apex endpoint to a callout: URL so the named credential holds the URL and authentication, and your code holds no credentials.
A named credential is one definition that holds the URL of a callout endpoint and the authentication that endpoint needs. When an Apex callout uses a named credential as its endpoint, Salesforce manages all authentication, so your code doesn't have to. In a custom B2B checkout integration, any custom Apex call that makes outbound HTTP connections must reference a named credential, so no credentials are hard-coded in the code. Checkout integrations cover areas such as pricing, tax, shipping and inventory.
What your code does without a named credential
Without a named credential, your Apex code has to do all of this itself:
- Hard-code the full https endpoint.
- Store a username and password.
- Build the Authorization header, for example a BASIC header made with
EncodingUtil.base64Encode.
Coding OAuth by hand is even more complex, which makes OAuth an ideal use case for named credentials.
You can also skip remote site settings for the site defined in the named credential. Callouts to external sites otherwise require remote site settings.