RestContext クラス
名前空間
使用方法
System.RestContext クラスを使用して、Apex REST メソッドの RestRequest オブジェクトと RestResponse オブジェクトにアクセスします。
サンプル
次の例では、RestContext を使用して、Apex REST メソッドの RestRequest オブジェクトと RestResponse オブジェクトにアクセスする方法を示します。
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];
10 return result;
11 }
12
13}