Read REST API GET Parameters in Apex Class
Biswajeet
September 18, 2017 0 Comments
URL: /services/apexrest/AccountAPI?id=AccountId
Method: Get
1 2 3 4 5 6 7 8 9 10 | @RestResource (urlMapping= '/AccountAPI/*' ) global with sharing class AccountRESTService { @HttpGet global static Account getAccount() { RestRequest req = RestContext.request; String accountId = req.params.get( 'id' ); Account acc = [SELECT Id, Name FROM Account WHERE Id =: accountId]; return acc; } } |
URL: /services/apexrest/AccountAPI/AccountId
Method: Get
1 2 3 4 5 6 7 8 9 10 11 | @RestResource (urlMapping= '/AccountAPI/*' ) global with sharing class AccountRESTService { @HttpGet global static Account getAccount() { RestRequest req = RestContext.request; String accountId = req.requestURI.substring(req.requestURI.lastIndexOf( '/' )+ 1 ); Account acc = [SELECT Id, Name FROM Account WHERE Id =: accountId]; return acc; } } |