Continuation Framework allows us to make synchronous callout as async callout ,which allows to get rid of Concurrent Limit platform error.

For making continuation work, all the logic of callout and processing should be moved from Utility classes to Page controller classes.

Isnt this more of code duplication? Or am i missing something?

I have around 10 VF pages that makes callout to an external endpoint, and that callout logic is in a Utility class.

Now making that callout as Async will make me copy paste same logic into controller, thus making me rework whats already done fro 10 pages.

Is there any proper way to do so? Controller/Extension inheritance is best i could come up with. Has anyone faced this architecture issue?

References : https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_continuation_callout_soap.htm


Only the code for creating the Continuation and the callback handler need to be in the controller. The code to create the HttpRequest and then handle the HttpResponse can still be in your utility class.


public class UtilityClass {

    public HttpRequest CreateRequestForX() {
        // Create your request here

    public void HandleResponseForX(HttpResponse response) {
        // Handle you response here

Then in your controller:

public static Object callService(Integer count){

    HttpRequest req = Utility.CreateRequestForX();

    Continuation con = new Continuation(60);
    con.state = con.addHttpRequest(req);
    con.continuationMethod = 'callback';        

    return con;

public static Object callback(Object state) {

    HttpResponse response = Continuation.getResponse((String)state);

| improve this answer | |

I don't think you will need code duplication for the when enforcing callout.

I did a similar exercise of having continuation on multiple VF pages. We are able to leverage/reuse most of the utility class.

The only requirement is that the callback functions needs to be in the same class as the continuation.

Here is a pseudocode/structure that I followed to leverage reusability

public Continuation calloutContoller() {
  //call utility to build the request
  Continuation c = new Continuation();
  con.continuationMethod = 'callbackMethod'
  //call the WS

public PageReference callBackMethod() {
   //Call Utility Methods
| improve this answer | |

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.