Create a custom Salesforce Apex REST endpoint using @RestResource to handle GET and POST requests from external systems

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 a global class with @RestResource(urlMapping='/your-resource/*') to register it as a REST endpoint under /services/apexrest/your-resource/
  2. Annotate methods with @HttpGet, @HttpPost, @HttpPut, @HttpPatch, or @HttpDelete; methods must be global static and accept no parameters (use RestContext.request to read the body and URL parameters)
  3. Parse the request body from RestContext.request.requestBody.toString() and deserialize it using JSON.deserialize() into a typed Apex class
  4. Build the response by setting RestContext.response.responseBody, statusCode, and headers, or simply return a typed object from the method for automatic JSON serialization
  5. Authenticate external callers using Connected App OAuth (JWT or auth code flow) and ensure the running user's profile has API access enabled
  6. Test using RestRequest and RestResponse instances set on RestContext.request and RestContext.response before calling the method in a test class

Known gotchas

Related routes

Create a custom Apex REST endpoint with @RestResource and handle multipart request routing for GET and POST verbs
developer.salesforce.com · 6 steps · unrated
Expose a custom Salesforce Apex REST endpoint using @RestResource and handle GET/POST with typed request/response classes
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