- SalesforceChaCha
- Posts
- ๐ Send multiple requests with a single REST callout ๐บ
๐ Send multiple requests with a single REST callout ๐บ
This not-so-new feature can optimize your integrations ๐คฏ
Good morning, Salesforce Nerds! With all of us being the top-notch Salesforce professionals that we are ๐ฏ, we all understand how critical integrations are within our system landscape.
Most of the time our attention gravitates toward outbound integrations - that is, how will Salesforce send/retrieve data to an external system. ๐ค
Today, however, letโs give some love to the inbound side of our integration projects! ๐
Letโs take a peek at the Composite API โฆ ๐

Agenda for today includes
Send multiple requests with a single REST callout
Daily Principle
All the Memes
Send multiple requests with a single REST callout
The mothership has provided a ๐ฉ-ton of ways to connect to the platform and execute business logic. But, sometimes it can get squirrelly ๐ฟ๏ธ orchestrating all that logic in a way that achieves the business goal in an efficient way.
Letโs look at an example for illustration purposes - suppose we have the following business requirement:
โOur homegrown .NET app is responsible for sending REST calls to our Salesforce instance to create an Account and multiple Contacts under the new Account.โ
From a developerโs perspective, we can approach this may ways.
1๏ธโฃ We can create a custom endpoint in Salesforce that will accept a JSON payload we can write code against to create the Accounts & Contacts in a single request. ๐ซ
2๏ธโฃ We can direct the .NET team to use standard endpoints and just split their operations across multiple requests. Meaning, first create the Account with a REST call, then use response from that request to assign the Contacts to the Account, followed by sending the Contact creation REST request. ๐
Any of these options will work โฆ technically speaking. But, if we want optimize this integration request and ensure the .NET team has a happy experience then we should seriously consider option #3๏ธโฃ !
This is a standard endpoint that wonโt require any of your Salesforce teamโs bandwidth! ๐๏ธ๐๏ธ
So what is it? โ๏ธ
Iโm glad you asked ๐ฅฐ
The Composite API allows developers to:
โ Construct a payload that represents multiple requests, into a single REST call. ๐คฏ
โ Use the output of one sub-request as the input of a subsequent sub-request inside the call. ๐
โ Save on API limits! These count as a single API call call! ๐๐บ
Check out the following example payload (straight from the dev guide):

We see a single JSON object representing the payload weโre going to send to the Composite API. Denoted by the compositeRequest
key at the beginning of the payload.
This compositeRequest
is made up of an array (a collection) of sub-requests. These sub-requests are executed under the same user context and in the order they are defined in the payload. ๐๐
Each sub-request contains:
โ๏ธ method
- identifies the CRUD operation to perform
โ๏ธ url
- denotes the resource weโre accessing
โ๏ธ referenceId
- designates the name of the variable holding the output data
โ๏ธ body
- body of that sub-request
Within the body
of each you can reference variables holding the results of previously executed sub-requests! ๐ง
This is a super powerful endpoint the platform offers! The next time you hear a request about how to best insert related data into your Salesforce instance through a REST integration give this a serious look! ๐ค
Daily Principle
"Everything is born from change."
and now....Your Daily Memes



What did you think about today's newsletter? |