Expose a custom Salesforce Apex REST endpoint using @RestResource and handle GET/POST with typed request/response classes

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. Annotate an Apex class with @RestResource(urlMapping='/myresource/*') and mark methods with @HttpGet or @HttpPost
  2. Use RestContext.request and RestContext.response to access the raw request body, path parameters, and set status codes
  3. Define inner Apex classes for request and response payloads and use JSON.deserialize / JSON.serialize for marshalling
  4. Deploy the class and verify the endpoint is accessible at /services/apexrest/<namespace>/myresource/
  5. Call the endpoint externally using a connected app OAuth token in the Authorization header
  6. Write Apex test methods that set RestContext.request manually to achieve code-coverage without making real HTTP calls

Known gotchas

Related routes

Create a custom Salesforce Apex REST endpoint using @RestResource to handle GET and POST requests from external systems
developer.salesforce.com · 6 steps · unrated
Create a custom Apex REST endpoint with @RestResource and handle multipart request routing for GET and POST verbs
developer.salesforce.com · 6 steps · unrated
Call a custom Salesforce Apex REST endpoint from an external system
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