Friday, 27 December 2019

Test Rest Service Using Postman/Workbench

  • Postman is an API collaboration platform used by over 17 million people. While Postman does much more, it’s most frequently used as an API client. Developers use Postman to send API calls and inspect what comes back.  
  • Review below Postman/RestService demo video -

 
Apps that are hosted on a secure server use the web server authentication flow. 1)To get the access token, follow the below steps -https://login.salesforce.com/services/oauth2/token.
 

2) To extract the record, do a get request and in headers section add Authorization 


3) To do a Post request through workbench, follow the below steps -


Apex Class Code -
@RestResource(urlMapping='/api/Account/*')global class MyFirstRestAPIClass { @HttpGet global static Account doGet() { RestRequest req = RestContext.request; RestResponse res = RestContext.response; String AccNumber = req.requestURI.substring(req.requestURI.lastIndexOf('/')+1); Account result = [SELECT Id, Name, Phone, Website FROM Account WHERE AccountNumber = '12345' ]; return result; } @HttpDelete global static void doDelete() { RestRequest req = RestContext.request; RestResponse res = RestContext.response; String AccNumber = req.requestURI.substring(req.requestURI.lastIndexOf('/')+1); Account result = [SELECT Id, Name, Phone, Website FROM Account WHERE AccountNumber = '12345' ]; delete result; } @HttpPost global static String doPost(String name,String phone,String AccountNumber ) { Account acc = new Account(); acc.name= name; acc.AccountNumber =AccountNumber ; insert acc; return acc.id; } }
 
To review the limits
/Services/data/v50.0/limits

2 comments:

  1. Wow, amazing blog layout! How long have you been blogging for? you make blogging look easy. The overall look of your web site is great, let alone the content!cloud contact centre features

    ReplyDelete
  2. No doubt this is an excellent post I got a lot of knowledge after reading good luck. Theme of blog is excellent there is almost everything to read, Brilliant post. Atlanta Limousine

    ReplyDelete