Rest API Call for GET and POST

@RestResource(urlMapping=’/Account/*’)
global with sharing class MyRestResource {

@HttpGet
global static Account doGet() {
RestRequest req = RestContext.request;
RestResponse res = RestContext.response;
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 String doPost(String name,
String phone, String website) {
Account account = new Account();
account.Name = name;
account.phone = phone;
account.website = website;
insert account;
return account.Id;
}
}

OUTPUT->

  1. GET – call following URL in workbench rest explorer”https://instance.salesforce.com/services/apexrest/Account/accountId”
  2. POST -“https://instance.salesforce.com/services/apexrest/Account/”

    JSON Format-

{
“name” : “Wingo Ducks”,
“phone” : “707-555-1234”,
“website” : “www.wingo.ca.us”
}

 

 


Need more help?

Hi there, was your problem or query resolved? If not & need more assistance, please do reach out to us at info@nanostuffs.com, we'll be more than delighted to help. Nanostuffs has 7+ years of extensive Salesforce & iOS/Android experience.
Holler Box