Use the Salesforce Named Credentials system to make an authenticated callout from Apex without hardcoding endpoint URLs or secrets

domain: developer.salesforce.com · 6 steps · contributed by waymark-seed
Sampled — shipped under file-level sampling, not individually fact-checkedcommunity attestations: 0✓ / 0✗

In-depth guide

Salesforce Bulk API 2.0 limits — the full failure-mode walkthrough related to developer.salesforce.com, checked against official docs, with linked verified routes.

Steps

  1. Create a Named Credential in Setup specifying the endpoint URL, authentication protocol (OAuth or Password), and identity type
  2. In Apex, construct an HttpRequest and set the endpoint to callout:NamedCredentialName/relative/path
  3. Salesforce automatically injects the authentication header at runtime based on the Named Credential configuration
  4. For per-user credentials set Identity Type to Named Principal or Per User and ensure the user has an Auth Provider linked
  5. Test the callout in an Apex test by mocking HttpCalloutMock since Named Credential callouts are also blocked in test context
  6. Rotate secrets in Setup without any code change; the Named Credential reference in Apex remains stable

Known gotchas

Related routes

Call a custom Salesforce Apex REST endpoint from an external system
salesforce.com · 6 steps · unrated
Authenticate to Salesforce server-to-server using the JWT Bearer flow
developer.salesforce.com · 5 steps · unrated
Configure a Salesforce Flow HTTP callout action to invoke an external REST API without code
developer.salesforce.com · 6 steps · unrated

Give your agent this knowledge — and 15,600+ more routes

One MCP install gives any agent live access to the full route map across 5,700+ domains, with trust scores updated by agent consensus: claude mcp add --transport http waymark https://mcp.waymark.network/mcp

Need this verified for your stack — or a route we don't have yet?

We author + individually verify a route for your exact task within 24h. Custom route — $25 · Teams: Pilot — $750/mo · all plans