Introduction:
In this blog post, I will explain how to use the composite API in Salesforce using a case replication scenario.
Prerequisite:
Go through blog post SAP Cloud Integration with Salesforce - Part 1 to understand the scenario, prerequisite setup and previous design solution.
What is Composite API?
It executes a series of REST API requests in a single call. The output of one request is used as the input for subsequent requests.
Help Link:
Composite API
Design Solution in Cloud Integration:
Integration Flow
Step 1:
Configure Sender Channel as below.
HTTPS Sender Channel
Step 2:
Call Local Integration Process via Process Call.
Step 2.a:
Convert incoming JSON message to XML using JSON to XML Converter.
Step 2.b:
Use Message Mapping to map the input structure to composite API XSD structure. The XSD structure for sObject can be downloaded from the Eclipse plugin – Salesforce Adapter Workbench. Select the following sObjects, Account, Contact and Case for creating the XSD structure (as shown below).
XSD Generator
Message Mapping
Parameter 'allOrNone'
Set it as true. It is used to specify what to do when an error occurs while processing a sub-request. If this flag is set as 'true', the entire request is rolled back. If it is set as 'false', the remaining sub-requests that don’t depend on the failed sub-requests are executed.
Sub-Request for Account
Sub-Request for Account
It is used to get AccountId from Salesforce based on input AccountNo.
Mapping Rule for Account Sub-Request
Sub-Request for Contact
It is used to get ContactId from Salesforce based on input RequestorEmail.
Mapping Rule for Contact Sub-Request
Sub-Request for Case
The value of AccountId and ContactId are retrieved from the output of previous sub-requests.
Mapping Rule for Case Sub-Request
Step 2.c:
Use Request Reply step to send data to Salesforce.
Receiver Salesforce Adapter
Step 2.d:
Use Router to determine if the case object is created or not.
Router
Step 2.e:
Use Content Modifier to prepare a response body for the success route.
Response Payload for Success Route
Step 2.e':
Use Content Modifier to prepare a response body for the failure route.
Response Payload for Failure Route
Test Execution:
Test Case 1: Success Scenario
Response Received from Salesforce
Test Case 2: Failure Scenario
Response Received from Salesforce
Conclusion:
- Composite API reduces the number of round-trips between SAP Cloud Integration and Salesforce.
- In a sub-request, a reference ID is specified that maps to the sub-request's response. The ID can be referred in the later sub-requests.
- An error in a sub-request causes either the whole composite request to roll back or the dependent sub-requests to roll back, which can be configured.
Thank you for reading this blog post. Please feel free to share your feedback or thoughts or ask questions in the Q&A tag below.
QA link
Regards,
Priyanka Chakraborti
Previous - Part 1 | Next - Part 3