SAP Cloud Integration with Salesforce – Part 2
In this blog post, I will explain how to use the composite API in Salesforce using a case replication scenario.
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:
Configure Sender Channel as below.
Call Local Integration Process via Process Call.
Convert incoming JSON message to XML using JSON to XML Converter.
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).
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
It is used to get AccountId from Salesforce based on input AccountNo.
Sub-Request for Contact
It is used to get ContactId from Salesforce based on input RequestorEmail.
Sub-Request for Case
The value of AccountId and ContactId are retrieved from the output of previous sub-requests.
Use Request Reply step to send data to Salesforce.
Use Router to determine if the case object is created or not.
Use Content Modifier to prepare a response body for the success route.
Use Content Modifier to prepare a response body for the failure route.
Test Case 1: Success Scenario
Test Case 2: Failure Scenario
- 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.