8

The maximum value for HttpRequest.setTimeout function is two minutes. How can we design an Apex class to receive the response if the response time is always guaranteed to be more than two minutes?

In the statement, HTTPResponse res = http.send(req), I want to execute the RHS to send the request immediately, but want to execute the LHS assignment ten minutes later.

19

Salesforce now allows Apex developers to invoke Asynchronous Callouts. This means that now, developers can initiate callouts from within Salesforce which can respond back in more than 2 minutes (governor limits) and assign a callback mechanism, to handle response for such callouts.

The mechanism is called continuation, wherein all such asynchronous requests are submitted to a Salesforce continuation server, along with a callback method. Continuation server takes care of web service invocation. Once continuation server receives a response from web service host, it calls the callback method specified during invocation.

With this, visualforce pages can be designed in a way that they submit an asynchronous request and continue with rest of the process. As soon as response is received an async method is called which can take care of the related business process (update records, refresh VF Page etc.)

For more details refer :- https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_continuation_overview.htm

https://developer.salesforce.com/blogs/engineering/2014/05/put-apex-sleep-salesforce-asynchronous-callouts.html

3

@Anshul provided an Amazing answer on how to handle callouts in async way. But still the question here is"The maximum callout time is 120,000 milliseconds" i.e You can't go beyond 2mins via any async method . Here now you would have to change the architecture of your application.

The answer would be to split the transaction into two calls.

  1. The endpoint will provide just ack id without full processing.
  2. After processing data the server will call our webservice providing the result with ack id. You query the particular record and perform DML. Thats how you utilize the platform to its full capability without have to worry about long callouts.

Callout Timeout limits here.

The integration pattern I am talking about is "Fire and Forget". You can read more about it here.

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.