Continuation object in Apex – Asynchronous callouts for long running request – Live Demo

We may run into scenario in Salesforce project, where we need call external web service but no need to wait for response. Response from external web service can be processed asynchronously and once processed it can be presented in Visualforce page.

We can accomplish this by using Actionsupport or Javascript remoting. However, this is possible with using Continuation method as well.  In Continuation approach, we can call external web service and inform that which callback method should be used to  process response. After execution of callback method, data is presented in visualforce page.

Execution Flow of an Asynchronous Callout - Image from Salesforce documentation
Execution Flow of an Asynchronous Callout – Image from Salesforce documentation

Below code demonstrate complete usage of this.

Continue reading “Continuation object in Apex – Asynchronous callouts for long running request – Live Demo”