Skip to content

Instantly share code, notes, and snippets.

@joshbirk
Created January 7, 2012 00:36
Show Gist options
  • Save joshbirk/1573251 to your computer and use it in GitHub Desktop.
Save joshbirk/1573251 to your computer and use it in GitHub Desktop.
Preview of some of the changes to Apex REST in version 24.0
@RestResource(urlMapping='/FieldCase/*')
global class ApexRESTUpdate {
//Note we no longer need to include RestRequest and RestResponse as incoming parameters
//The static RestContext has request and response properties instead
@HttpGet
global static List<Case> getOpenCases() {
String companyName = RestContext.request.params.get('companyName');
Account company = [ Select ID, Name, BillingState from Account where Name = :companyName];
List<Case> cases = [SELECT Id, Subject, Status, OwnerId, Owner.Name from Case WHERE AccountId =: company.Id];
return cases;
}
//Here we are using CaseSummary as an incoming parameter, which is an Apex class not an SObject.
//Previously, you could not use user defined params
@HttpPost
global static String createCase(CaseSummary cs) {
Case c = new Case();
c.Subject = cs.CaseExternalID + cs.CaseDescription;
insert c;
return c.Subject;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment