Make Long-Running Callouts with Continuations
Continuation class in Apex to make a long-running request to an external web service. Process the response in a callback method. Continuations are the preferred way to manage callouts because they can provide substantial improvements to the user experience.
Using continuations has some advantages, including the capability to make callouts in parallel.
The framework queues up actions before sending them to the server. This mechanism is largely transparent to you when you’re writing code but it enables the framework to minimize network traffic by batching multiple actions into one request (XHR). The batching of actions is also known as boxcar’ing, similar to a train that couples boxcars together. Since continuations can be long-running requests, the framework essentially treats continuations as background actions. Continuations aren't boxcar'ed with other requests so they don't block other actions while they are running.
An asynchronous callout made with a continuation doesn’t count toward the Apex limit of synchronous requests that last longer than five seconds. Since Winter ‘20, all callouts are excluded from the long-running request limit so continuations no longer offer an advantage for working with limits compared to regular callouts. However, we recommend using continuations to manage callouts due to the improved user experience.
- Batching of Apex Actions
- Apex Reference Guide: Continuation Class
- Apex Developer Guide: Named Credentials as Callout Endpoints