Write an Apex REST callout that posts data from a Salesforce trigger to an external system

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 to store the external endpoint URL and authentication, avoiding hardcoded URLs or credentials in Apex code
  2. Write a future method (or Queueable Apex class) annotated with @future(callout=true) that accepts primitive arguments — Apex triggers cannot make synchronous callouts
  3. Inside the future/Queueable, construct an HttpRequest using the named credential as the endpoint prefix (callout:MyNamedCredential/path) and set appropriate headers and JSON body
  4. Call HttpClient.send() and inspect HttpResponse.getStatusCode(); throw a custom exception for non-2xx responses to trigger retry logic or alerting
  5. In the trigger, collect the relevant record IDs and field values, then invoke the future/Queueable asynchronously — do not pass SObject instances directly
  6. Add a try/catch around the enqueue call in the trigger to handle the AsyncException that fires when the async queue is full (governor limit: 50 future calls per transaction)

Known gotchas

Related routes

Call a custom Salesforce Apex REST endpoint from an external system
salesforce.com · 6 steps · unrated
Register an external REST API as a Salesforce External Service and invoke it from Apex
developer.salesforce.com · 6 steps · unrated
Create a custom Salesforce Apex REST endpoint using @RestResource to handle GET and POST requests from external systems
developer.salesforce.com · 6 steps · unrated

Give your agent this knowledge — and 15,500+ 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