Note: This release is in preview. Features described here don’t become generally available until the latest general availability date that Salesforce announces for this release. Before then, and where features are noted as beta, pilot, or developer preview, we can’t guarantee general availability within any particular time frame or at all. Make your purchase decisions only on the basis of generally available products and features.
RestContext Class
Namespace
Usage
Use the System.RestContext class to access the RestRequest and RestResponse objects in your Apex REST methods.
Sample
The following example shows how to use RestContext to access the RestRequest and RestResponse objects in an Apex REST method.
1@RestResource(urlMapping='/MyRestContextExample/*')
2global with sharing class MyRestContextExample {
3
4 @HttpGet
5 global static Account doGet() {
6 RestRequest req = RestContext.request;
7 RestResponse res = RestContext.response;
8 String accountId = req.requestURI.substring(req.requestURI.lastIndexOf('/')+1);
9 Account result = [SELECT Id, Name, Phone, Website FROM Account WHERE Id = :accountId WITH USER_MODE];
10 return result;
11 }
12
13}RestContext Properties
The following are properties for RestContext.
request
Signature
public RestRequest request {get; set;}
Property Value
Type: System.RestRequest
response
Signature
public RestResponse response {get; set;}
Property Value
Type: System.RestResponse