By: Urmila Pawar
Why do we need to build an API in Salesforce?
We customize and automate the functionality within Salesforce. But what if the external system wants to communicate with Salesforce and utilize these functionalities? In order to solve this barrier we create API, so that the external systems can read data from Salesforce, or write data to Salesforce.
API Basics
An API is a way to communicate with a component without bothering with its internal functionality. An API usually expects input in a specific format, and responds in a specific format as well.
SOAP vs REST API
| SOAP | REST API |
| SOAP stands for Simple Object Access Protocol | REST stands for Representational States Transfer |
| SOAP is a protocol | REST is an architectural pattern |
| SOAP uses service interfaces to expose its functionality to client applications | REST uses Uniform Service locators to access the components on the hardware device |
| SOAP needs more bandwidth for its usage | REST works with lower bandwidth |
| SOAP only works with XML formats | REST works with plain text, XML, HTML, and JSON |
| SOAP cannot make use of REST | REST can make use of SOAP |
Creating Connected App in Salesforce
You can follow the Salesforce Trailhead links to create a connected app. https://trailhead.salesforce.com/en/content/learn/projects/build-a-connected-app-for-api-integration/create-a-connected-app
REST API Communication Flow

REST Annotation
We can expose your Apex class and methods so that external applications can access your code and your application through the REST architecture.
- We use @RestResource annotation to expose it as a REST resource
- We can add the @HttpDelete annotation to your method to expose it as a REST resource that can be called by an HTTP DELETE request
- We can add the @HttpGet annotation to your method to expose it as a REST resource that can be called by an HTTP GET request
- We can add the @HttpPost annotation to your method to expose it as a REST resource that can be called by an HTTP POST request
- We can use the System.RestRequest class to access and pass request data in a RESTful Apex method.
- Represents an object used to pass data from an Apex RESTful Web service method to an HTTP response.
@RestResource(urlMapping=’/CustomAPI/*’)
global with sharing class CustomResource {
@HttpDelete
global static void doDelete() {
//some delete operation here
}
@HttpGet
global static CustomInfo doGet() {
//some query operation here
//return queried information
}
@HttpPost
global static String doPost(String name,
//some dml operation here
//return the ID of recently created record
}
}
Example
@RestResource(urlMapping=’/OrderProcessor/*’)
global with sharing class OrderProcessingResource {
@HttpGet
global static CustomInfo doGet() {
RestRequest request = RestContext.request;
RestResponse response = RestContext.response;
String ordertId = req.requestURI.substring(req.requestURI.lastIndexOf(‘/’)+1);
Order orderWithLineItems = [SELECT Id, (SELECT Id, Name FROM OrderLineItems)
FROM Order
WHERE Id = :ordertId];
return orderWithLineItems;
}
}
Calling API from External System
1. Authentication Request
Salesforce token request endpoint
Production : https://login.salesforce.com/services/oauth2/token
Sandbox : https://test.salesforce.com/services/oauth2/token
We are using Username Password Flow for Authentication.
Following request fields are required:
- grant_type : Must be password for this authentication flow.
- client_id : The Consumer Key from the connected app definition.
- client_secret : The Consumer Secret from the connected app definition. Required unless the Require Secret for Web Server Flow setting is not enabled in the connected app definition.
- username : End-user’s username.
- password : End-user’s password. You must append the user’s security token to their password
Sample URL :
https://test.salesforce.com/services/oauth2/token?grant_type=password&client_id=xxxxxxxxxxxxxxxxxxxxxx&client_secret= xxxxxxxxxxxxxxxxxxx&username= user@test.com.sandbox&password=password+securitytoken
Sample Response :
{
“access_token”: “xxxxxxxxxxxxxxxxxxxxxxxx”,
“instance_url”: “https://sandbox.cs70.my.salesforce.com”,
“id”: “https://test.salesforce.com/id/00Dxxxxxxxxxxxx/005xxxxxxxxxxxx”,
“token_type”: “Bearer”,
“issued_at”: “1549347983877”,
“signature”: “xxxxxxxxxxxxxxx=”
}
2. GET Order Request
From the response received as part of the authentication request please note the “access_token” and “instance_url”. These will be required for further request.
Method Type : GET
URL : instance_url+’/services/apexrest/OrderProcessor/’+orderId
For Example : https://cs27.salesforce.com/services/apexrest/OrderProcessor/801xxxxxxxxxxxxxxx
Parameters :
| content-type | application/xml |
| authorization | Bearer access_token |
Sample Response:
{
“Order”: {
“Id”: “801xxxxxxxxxxxxxxx”,
“OrderLineItems”: [{
“Id”: “802xxxxxxxxxxxxxxx”
}]
}
}
https://t.me/s/pt1win/423
Актуальные рейтинги лицензионных онлайн-казино по выплатам, бонусам, минимальным депозитам и крипте — без воды и купленной мишуры. Только площадки, которые проходят живой отбор по деньгам, условиям и опыту игроков.
Следить за обновлениями можно здесь: https://t.me/s/reitingcasino
https://t.me/s/iGaming_live/4545
https://t.me/iGaming_live/4658
https://t.me/reyting_topcazino/12
https://t.me/of_1xbet/1011
https://t.me/s/ef_beef
Your point of view caught my eye and was very interesting. Thanks. I have a question for you. https://accounts.binance.com/ru-UA/register?ref=JVDCDCK4
Thank you for your sharing. I am worried that I lack creative ideas. It is your article that makes me full of hope. Thank you. But, I have a question, can you help me? https://www.binance.info/fr/register?ref=T7KCZASX
Thanks for sharing. I read many of your blog posts, cool, your blog is very good. https://accounts.binance.com/cs/register-person?ref=OMM3XK51
https://t.me/officials_pokerdom/3468
https://t.me/officials_pokerdom/3967
Thank you for your sharing. I am worried that I lack creative ideas. It is your article that makes me full of hope. Thank you. But, I have a question, can you help me?
Thank you for your sharing. I am worried that I lack creative ideas. It is your article that makes me full of hope. Thank you. But, I have a question, can you help me? https://www.binance.info/zh-TC/register?ref=DCKLL1YD
https://t.me/s/iGaming_live/4871
https://t.me/dragon_money_mani/39
Downloaded the 55betcasinoapp the other day. Pretty smooth, easy to use on the go. If you’re into mobile gaming, it’s worth a download. Here’s the link: 55betcasinoapp
Thanks for sharing. I read many of your blog posts, cool, your blog is very good. https://accounts.binance.info/register-person?ref=IXBIAFVY
Thanks for sharing. I read many of your blog posts, cool, your blog is very good. https://www.binance.info/en-ZA/register?ref=B4EPR6J0
Your article helped me a lot, is there any more related content? Thanks! https://accounts.binance.com/register-person?ref=IXBIAFVY
**mitolyn reviews**
Mitolyn is a carefully developed, plant-based formula created to help support metabolic efficiency and encourage healthy, lasting weight management.
**prodentim**
ProDentim is a distinctive oral-care formula that pairs targeted probiotics with plant-based ingredients to encourage strong teeth, comfortable gums, and reliably fresh breath.
Sway goodbye to on tenterhooks nights with THCA bud indica or [url=https://www.hipuffy.com/collections/thc-a-flower ]thc-a flower for sale[/url] . In behalf of centuries, indica strains include been eminent as disposition’s furthest nightcap. When heated, the activated cannabinoids vocation in unanimity to pacific a racing mind and calm somatic restlessness. Elevate your bedtime custom, profit from the money, vulgar aromas, and course afar into a intensely, uninterrupted, and truly restorative sleep.
If your inborn traffic has plateaued, hiring a shopify seo experienced strength like https://www.linkedin.com/pulse/shopify-seo-brands-cant-scale-paid-ads-cases-dmitri-bezdetny-enfuf/ be your excellent move. True shopify seo experts know the dais’s unique URL quirks, amassment structures, and coding infrastructure. A acclimatized seo shopify virtuoso wish audit your store, install hidden errors, and build a tailored roadmap to direct search impressions into paying customers.
handle yourself to the best of both worlds with our top-shelf production. https://www.hipuffy.com/collections/hybrid-gummies Our inventorying have high-pitched thca flower for cut-rate sale aboard premium thca hemp flower and artisanal sativa edible gummies, giving you tote up hold in ended how you opt to lift your sidereal day. Whether you favor rolling up new organic thca flower, packing material fresh thca indoor flower, or microdosing with a toothsome hybrid viscid or thc gummies hybrid select, we let you all cover. tick off out our up-to-the-minute thca flower on cut-rate sale now, keep handsome with our budget thca flower lines, and savor quick merchant marine.
Thinking about it, around digital gambling, I’ve recently noticed that modern sites have completely transformed the way players play slots . Honestly, it seems that the odds are often totally volatile, which proves that careful bankroll management is the real key in this hobby. Anyway, I checked out this cool resource [url=https://telegra.ph/%CE%91%CE%B9%CF%87%CE%BC%CE%AE-%CF%84%CE%BF%CF%85-%CE%B4%CF%8C%CF%81%CE%B1%CF%84%CE%BF%CF%82-%CE%B7-%CE%B2%CE%B9%CE%BF%CE%BB%CE%BF%CE%B3%CE%AF%CE%B1-%CE%95%CE%BE%CE%B5%CE%BB%CE%AF%CE%BE%CE%B5%CE%B9%CF%82-%CE%B9%CE%B1%CF%84%CF%81%CE%B9%CE%BA%CE%AD%CF%82-%CE%BA%CE%B1%CE%B9%CE%BD%CE%BF%CF%84%CE%BF%CE%BC%CE%AF%CE%B5%CF%82-%CE%BA%CE%B1%CE%B9-%CE%BF-%CE%BC%CE%B5%CF%84%CE%B1%CF%83%CF%87%CE%B7%CE%BC%CE%B1%CF%84%CE%B9%CF%83%CF%84%CE%B9%CE%BA%CF%8C%CF%82-%CF%81%CF%8C%CE%BB%CE%BF%CF%82-%CF%84%CF%89%CE%BD-Bio-%CE%9D-04-14]https://telegra.ph/Beyond-the-Headlines-Real-Time-Updates-Shaping-Online-Entertainment-News-04-14[/url]
https://telegra.ph/Beyond-the-Headlines-Real-Time-Updates-Shaping-Online-Entertainment-News-04-14 where users share various betting systems, and I found it quite valuable for keeping my risks low . A major point I constantly advise others is to avoid trying to run after losses , because that’s usually when things turns bad. Over the last few weeks, I’ve also been thinking whether the real-time croupier tables truly offer a fairer vibe than regular digital software . What do you guys thoughts on this, and have you noticed any reliable trends lately ? Let’s chat going in this thread!
Thinking on my experience, around virtual wagering, I’ve realized how the latest platforms have completely transformed the way players experience tables. In my opinion, it feels that the house edge tend to be quite unpredictable, which proves that smart bankroll management is vitally crucial in this hobby. Anyway, I ran into this interesting platform [url=https://telegra.ph/%CE%91%CE%B9%CF%87%CE%BC%CE%AE-%CF%84%CE%BF%CF%85-%CE%B4%CF%8C%CF%81%CE%B1%CF%84%CE%BF%CF%82-%CE%B7-%CE%B2%CE%B9%CE%BF%CE%BB%CE%BF%CE%B3%CE%AF%CE%B1-%CE%95%CE%BE%CE%B5%CE%BB%CE%AF%CE%BE%CE%B5%CE%B9%CF%82-%CE%B9%CE%B1%CF%84%CF%81%CE%B9%CE%BA%CE%AD%CF%82-%CE%BA%CE%B1%CE%B9%CE%BD%CE%BF%CF%84%CE%BF%CE%BC%CE%AF%CE%B5%CF%82-%CE%BA%CE%B1%CE%B9-%CE%BF-%CE%BC%CE%B5%CF%84%CE%B1%CF%83%CF%87%CE%B7%CE%BC%CE%B1%CF%84%CE%B9%CF%83%CF%84%CE%B9%CE%BA%CF%8C%CF%82-%CF%81%CF%8C%CE%BB%CE%BF%CF%82-%CF%84%CF%89%CE%BD-Bio-%CE%9D-04-14]https://telegra.ph/Beyond-the-Headlines-Real-Time-Updates-Shaping-Online-Entertainment-News-04-14[/url]
https://telegra.ph/Beyond-the-Headlines-Real-Time-Updates-Shaping-Online-Entertainment-News-04-14 where people discuss different betting tips , and it’s been quite insightful to keep my risks down . One thing I always tell myself is to never track bad runs, because that’s usually how things goes wrong . Over the last few weeks, I’ve also been thinking whether the stream croupier tables actually give a fairer vibe than classic digital software . What’s your take on this whole thing, and have you noticed any reliable trends recently? Let’s get a discussion here below !