Posts

Showing posts from May, 2019

How to Build a Basic Salesforce REST API (With Test Class) and Test with POSTMAN

Image
Salesforce : Creating Anonymous Apex REST APIs with Force.com The Force.com REST API lets you integration with Force.com applications using standard HTTP methods. This API provides a way to expose the data you have within your Force.com application to external applications – both mobile and non-mobile. A few useful bits of information related to these REST APIs: This sample Code you how to implement a simple REST API to fetch Account in Apex class: @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; } } Call to REST Client (with Curl) : curl -H "Authorization: Bearer sessi