A detail look at the Salesforce Composite API

 

 

A detail look at the Salesforce Composite API

 

Doing data integration with Salesforce is not simple. We have to understand API objects which are analogous to database tables and KSQL to extract data from Salesforce, and different types of API set and when to use appropriately, and the concept of External Id… and limit of API calls.

With the Advantco Salesforce Adapter, we simplify the connectivity and transparently consume different API sets, so it makes the implementation more straightforward and faster.

 

The problem

Trying to make multiple API calls for a “simple” task and get exceeded API request limit?

Let examine an example of the sales order. SAP sends an sales order with a header and two order lines. It is not a simple example if we don’t want to say it’s a challenge in integration without adapter support.

We manually take care of the access token for every subsequence request calls to Salesforce by using Netweaver BPM or Java Mapping, and manually create mapping schema for each Salesforce object for REST/SOAP API calls…

To create an order header and several order lines, we need at least two requests to Salesforce. The first is to create the order header. In the second request, it looks up the created order header and then creates order lines. So we have to make sure these two requests execute in the right sequence, no other way.

A detail look at the Salesforce Composite API

The consequence of this restriction makes orders queue up when one of them failed in transmission to Salesforce.

In high throughput time, we may get the error of exceeding the API request limit if the number of requests is not managed well.

 

The solution

With the Advantco Salesforce adapter, the adapter supports session reuse to reduce the number of login call to Salesforce. So we maintain the connection and make a subsequent request in a single channel. It makes the integration flow clean, neither BPM needed nor an extra Java mapping to maintain the access token.

The choice of different types of API set is not a problem now. The adapter will do it. It’ll automatically select the appropriate API according to the feature we are using.

The schema is generated from the Advantco Salesforce Workbench, we don’t cover it in this topic, but it provides a ton of features such as Schema generation, SOQL editor, APEX client generator, Outbound Messaging (OBM)…

 

The implementation is faster and easier. But the queue up issue still.

You may know the Composite API. It helps to improve the performance by reducing round trip requests to Salesforce and minimize the number of API calls by batching up multiple calls to a single one.

With the Composite API support, we combine order header and order lines to a single request. It solves the problem. We don’t have to maintain the sequence of separate requests as earlier, so no more queue up and the transaction of each order is free from the other.

More important, it’s a lot easier to have a consistent transaction with the Composite request. Each batch of the Composite request can have up to 25 subrequests, and the batch is rolled back when an error occurs while processing a subrequest. It’s an optional configuration from the adapter.

The channel configuration using the Composite API.

A detail look at the Salesforce Composite API

 

The sample payload of the Composite request. The only difference from the payload of another API set is the field “referenceId”.

A detail look at the Salesforce Composite API

 

Look up the order header Id with the syntax “@{refQueryOrder.records[0].Id}”

The sample of message mapping.

A detail look at the Salesforce Composite API

 

Conclusion

So it’s straightforward to implement an integration scenario of sales order with the Composite API and the Advantco Salesforce Adapter.

In the real scenario, we may need to delete unused order lines along with adding new order lines and updating the existing lines. The sample payload we are using the operation UPSERT it means it already takes care of adding and updating existing, we need to add another subrequest of OrderDetail with an operation DELETE to delete unused order lines.

References

Advantco Salesforce Adapter https://https://www.advantco.com/sap-integration-adapters/sap-salesforce-integration

Salesforce Composite Resource https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/resources_composite.htm

 

Please reach out to our sales team at sales@advantco.com if you have any questions.