Continuation Class
Use the Continuation class to make callouts asynchronously to a SOAP or REST Web service.
For a code example, see Make Long-Running Callouts from a Visualforce Page.
The following are constructors for Continuation.
-
Creates an instance of the
Continuationclass by using the specified timeout in seconds. The timeout maximum is 120 seconds.
Creates an instance of the Continuation class by using the specified timeout in seconds. The timeout maximum is 120 seconds.
public Continuation(Integer timeout)
-
timeout:
Type: Integer
The timeout for this continuation in seconds.
The following are properties for Continuation.
-
The name of the callback method that is called after the callout response returns.
-
The timeout of the continuation in seconds. Maximum: 120 seconds.
-
Data that is stored in this continuation and that can be retrieved after the callout is finished and the callback method is invoked.
The name of the callback method that is called after the callout response returns.
public String continuationMethod {get; set;}
Type: String
If the continuationMethod property is not set for a Continuation, the same action method that made the asynchronous callout is called again when the callout response returns.
The timeout of the continuation in seconds. Maximum: 120 seconds.
public Integer timeout {get; set;}
Type: Integer
Data that is stored in this continuation and that can be retrieved after the callout is finished and the callback method is invoked.
public Object state {get; set;}
Type: Object
This example shows how to save state information for a continuation in a controller.
The following are methods for Continuation.
-
Adds the HTTP request for the callout that is associated with this continuation.
-
Returns all labels and requests that are associated with this continuation as key-value pairs.
-
Returns the response for the request that corresponds to the specified label.
Adds the HTTP request for the callout that is associated with this continuation.
public String addHttpRequest(System.HttpRequest request)
-
request:
Type: HttpRequest
The HTTP request to be sent to the external service by this continuation.
Type: String
A unique label that identifies the HTTP request that is associated with this continuation. This label is used in the map that getRequests() returns to identify individual requests in a continuation.
You can add up tothree requests to a continuation.
The timeout that is set in each passed-in request is ignored. Only the global timeout maximum of 120 seconds applies for a continuation.
Returns all labels and requests that are associated with this continuation as key-value pairs.
public Map<String,System.HttpRequest> getRequests()
Type: Map<String,HttpRequest>
A map of all requests that are associated with this continuation. The map key is the request label, and the map value is the corresponding HTTP request.
Returns the response for the request that corresponds to the specified label.
public static HttpResponse getResponse(String requestLabel)
-
requestLabel:
Type: String
The request label to get the response for.
Type: HttpResponse
The status code is returned in the HttpResponse object and can be obtained by calling getStatusCode() on the response. A status code of 200 indicates that the request was successful. Other status code values indicate the type of problem that was encountered.
Sample of Error Status Codes
When a problem occurs with the response, some possible status code values are:
2000: The timeout was reached, and the server didn’t get a chance to respond.2001: There was a connection failure.2002: Exceptions occurred.2003: The response hasn’t arrived (which also means that the Apex asynchronous callout framework hasn’t resumed).2004: The response size is too large (greater than 1 MB).