Skip to content

Instantly share code, notes, and snippets.

@tvaidyan
Created May 14, 2021 15:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tvaidyan/060e8179822654299a150009a07b4556 to your computer and use it in GitHub Desktop.
Save tvaidyan/060e8179822654299a150009a07b4556 to your computer and use it in GitHub Desktop.
A Salesforce Apex Class defining a REST API
@RestResource(urlMapping='/v1/claim/')
global class ClaimController {
@httpGet
global static List<Claim__c> GetClaims(){
List<Claim__c> claims = new List<Claim__c>();
claims = [Select Name, FirstName__c, LastName__c, FavoriteColor__c From Claim__c];
return claims;
}
@httpDelete
global static String DeleteClaim(){
Claim__c claim = new Claim__c();
Map<String, String> paramsMap = RestContext.request.params;
String claimId = paramsMap.get('claimNumber');
claim = [Select Name, FirstName__c, LastName__c, FavoriteColor__c From Claim__c Where Name =: claimId];
delete claim;
return 'Record deleted';
}
@httpPost
global static Claim__c AddClaim(string FirstName, string LastName){
Claim__c claim = new Claim__c(FirstName__c = FirstName, LastName__c = LastName);
insert claim;
return claim;
}
@httpPut
global static Claim__c UpdateClaim(string ClaimNumber, string FavoriteColor){
Claim__c claim = [Select FavoriteColor__c From Claim__c Where Name =: ClaimNumber];
claim.FavoriteColor__c = FavoriteColor;
update claim;
return claim;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment