I am using Apex Continuation which has 2 functions:
startRequest() - the starting function
processResponse() - the callback function.


processResponse() is being called OK either...

  1. when I get a Response OR
  2. when the Continuation times out (number of seconds are given in the parameter).

However, processResponse() is not called when HttpRequest Endpoint is an invalid website (even after the timeout is reached).

How to handle Apex Continuation when the endpoint is an invalid website?

    public Object startRequest()
        // Create continuation with a timeout
        Continuation con = new Continuation(40); //40 seconds
        // Set callback method
        // Create callout request
        HttpRequest req = new HttpRequest();
        // Add callout request to continuation
        this.requestLabel = con.addHttpRequest(req);
        // Return the continuation
        return con;  

    // Callback method 
    public Object processResponse()
        // Get the response by using the unique label
        HttpResponse response = Continuation.getResponse(this.requestLabel);
        if(response != null && response.getBody() != null && response.getStatusCode() == 200)
  • Can you provide sample endpoint? I have provided a fake endpoint and it gives me 400 error. – Pranay Jaiswal Aug 6 '18 at 17:24
  • @PranayJaiswal any invalid website should do. If you are getting a 400 error, there is something wrong in my VF then. Checking... – Shumon Saha Aug 6 '18 at 17:35
  • I checked... nothing wrong with my Class and VF because I copied the example (developer.salesforce.com/docs/atlas.en-us.apexcode.meta/…) from Salesforce and simply put in a URL in the placeholder. I am not getting a response code for any invalid URL such as fill1text.com but getting a response 200 from filltext.com – Shumon Saha Aug 6 '18 at 17:48

Your Answer

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

Browse other questions tagged or ask your own question.