Created
May 14, 2021 15:51
-
-
Save tvaidyan/060e8179822654299a150009a07b4556 to your computer and use it in GitHub Desktop.
A Salesforce Apex Class defining a REST API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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