2

We are trying to integrate external system with Salesforce. Requirement is, whenever a record of a Custom object is created or updated in Salesforce, this event should synchronously call out to a RESTful API of the external system.

Since not being able to make synchronous callout from Apex Trigger is a well known limitation, is there a workaround we can use?

0

2 Answers 2

4

You should create a visualforce page and from there, submit a synchronous callout request to the external system.

visualforce callout

I have written my blog post Visualforce webservice callout synchronously & asynchronously on this.

1

It is common to perform such callouts from an @future method or a Queueable, which are fired asynchronously (but within a very short delay) from the trigger.

Salesforce limits make this challenging when working with integrated systems that require one callout per record. There is a limit of 100 callouts per transaction, with a cumulative 120 second total time limit. There's also a limit of 50 @future method invocations in a single transaction, so firing one future method per record in your trigger will hit limits immediately if you make any bulk data updates.

For a new implementation, I would recommend using a chained Queueable structure: in your trigger, enqueue a Queueable class, which would take as its parameter the Ids of the records that require syncing. Then, in the Queueable class, batch those records and perform callouts up to the transactional callout limit (100). Finally, the Queueable can chain-enqueue a new instance of itself, passing along any remaining Ids so they can be processed in a separate transaction with a new set of limits.

Hopefully, the system to which you are integrating can accept multiple records in a single call, which will lower your limits consumption and increase performance.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .