• 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.โ€

Brad, the devilishly good-looking IT Manager

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."

Marcus Aurelius

and now....Your Daily Memes

What did you think about today's newsletter?

Login or Subscribe to participate in polls.