Skip to content

Instantly share code, notes, and snippets.

@tzmfreedom
Created September 13, 2014 14:12
Show Gist options
  • Save tzmfreedom/8166aa68ec1e12cf4f94 to your computer and use it in GitHub Desktop.
Save tzmfreedom/8166aa68ec1e12cf4f94 to your computer and use it in GitHub Desktop.
@RestResource(urlMapping='/MyRestContextExample/*')
global with sharing class AnonymousHandler {
@HttpGet
global static Account doGet() {
RestRequest req = RestContext.request;
RestResponse res = RestContext.response;
res.addHeader('Access-Control-Allow-Origin', '*');
String accountId = req.requestURI.substring(req.requestURI.lastIndexOf('/')+1);
Account result = [SELECT Id, Name, Phone, Website FROM Account WHERE Id = :accountId];
return result;
}
@HttpPost
global static Boolean doPost() {
RestRequest req = RestContext.request;
RestResponse res = RestContext.response;
res.addHeader('Access-Control-Allow-Origin', '*');
return true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment