2

I have logic inside an Apex Class that will be invoked from a Lightning Component. There are three sequential callouts that will be sent to an External System whenever its method is Called.

As per the Salesforce Governor limits, if a transaction exceeds more than 5 seconds it will be considered a long-running transaction, and there cannot be more than 10 concurrent long-running transactions.

In my case, if each callout took 4 seconds on average, then it would take 12 seconds on average to execute all three callouts. Because this transaction has exceeded 5 secs it will be considered a long-running transaction.

What are the alternative approaches to handle this use case?

Maybe doing an Asynchronous Callout - Continuations method will help. The Continuations method is not yet supported directly from lightning. But we can invoke apex Continuations from lightning as mentioned in this blog.

Appreciate your Suggestions

  • Are you expecting that all three callouts will be run synchronously and the user will see the final result of the callout process? Because I'd far rather run them in a Queueable or multiple Queueables. – David Reed Nov 4 '18 at 11:21
  • @DavidReed - Our UseCase is to call these there Callouts Synchronously and Sequentially (one after the other) And we have to utilize one callout response in another callout request. – Red Rick Nov 4 '18 at 12:54
4

That's tricky. The first thing that comes to mind is to do it asynchronously and find a way to "subscribe" to the response. You can make use of Platform Events for this.

  1. Call your Apex class and either pass in or have it return a unique Id for the transaction.
  2. Run your sequential callouts in @Future context from your Apex class.
  3. When the transactions are complete, fire a platform event from your Apex class that includes the unique Id.
  4. In your lightning component, use the lightning:empApi to subscribe to to the Platform Event.
  5. When the event message containing the correct Id comes through, render the info on your component.

Note: You may have to watch out for Platform Event daily limits if your expected volume could reach 50,000.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.