function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Ron WildRon Wild 

System.CalloutException: Read timed out ... Is there any way to change the time out period?

I'm frequently getting the error "System.CalloutException: Read timed out" on an HTTP Service (RESTful) call I am making from an Apex class.

It doesn't appear to be a proxy/firewall issue as I *am* able to get a response.   I think I just have a slow server on the other end.

Is there any way to increase the timeout period on this call to ensure that the web service has time to respond?

Thanks!

Ron HessRon Hess
No, by design this timeout cannot be extended (or changed) it is 10 seconds.

You may be able to write a retry into your code, so that when you do catch() a timeout you can try one more time.

Ron WildRon Wild
I was afraid of that.

When the Callout times out, the operation has already been performed on the other end and I'm just waiting for the response.   If I make the call again, I will get duplicate transactions.   So essentially the call results are lost.




SuperfellSuperfell
This is a common problem with HTTP, if you have control of the server, you can re-work your api, so that the request includes a messageId, and have an additional call that returns the results for a given messageId, that way if the initial result is lost in transit, you can still work out the state of your first call.
Ron WildRon Wild
I've also found that the Callout feature requires that all database changes be committed before you can make a Callout.

I haven't seen anything in the docs on how to 'commit'.   Is there a database method I'm missing?  Something like Database.commit() ?

Thanks,
PhilForForcePhilForForce

Hi Ron,

Did you find a solution to your dataase.commit() issue?

I am having the same problems.

Thanks,

 

Phil

Sulabh KapoorSulabh Kapoor

Did anyone got an answer to this since I am facing the same issue?

Ulas KutukUlas Kutuk

You can use setTimeout to extend timeout duration here is the sample code I ve changed as 20 seconds. 

 

HttpRequest req = new HttpRequest();
req.setEndpoint(gv_APIEndpoint);
req.setMethod('POST');
req.setHeader(methodName, encodedData);
req.setBody( encodedData);
Http http = new Http();
req.setTimeout(20);
HTTPResponse res = http.send(req);
String nvp=res.getBody();
PayPalCallOutSuccess=true;

 

ForceCoderForceCoder

Just a quick clarification on UK1925's post...

 

The request.setTimeout Integer is milliseconds so calling it with 20 is NOT 20 seconds.  You'd want to call it with 20,000:

20 sec * 1000  ms / sec = 20,000 ms

 

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_classes_restful_http_httprequest.htm

 

Ulas KutukUlas Kutuk

Thats correct...Thanks for @ForceCoder

sfdcFanBoysfdcFanBoy

Setting the timeout to max also doesn't help. 

 

Any other suggestions please?

 

Thanks!

MukulGMukulG

Are you sure you are able to connect to the server? and the server is sending a response? Did you check the logs at the endpoint server?

 

Did you find a solution?

Daniela LeónDaniela León
I'm having the same issue, and I can't find how to solve it...  the request is not even being sent.... Could you please help!!!
John Peterson 2John Peterson 2
Hi All,

To increase the timeout inside of Apex class inside the imported WSDL you can set a property timeout_x to a millisecond value greater than 10 seconds.

Ex:

MySOAPClass stub = MySOAPClass.SalesforceListener();
stub.timeout_x = 60000;
Response_element response = stub.callSoapOperation(parameters);

- John
Layton EversonLayton Everson
For all of you facing the database.commit issue, the answer is to use a asynchronous apex to execute your call. When I am processing payment transactions, I have user or system initiated process that creates and stores a transaction record. Then a batch process runs, loading a single transaction at a time, that sends that transaction to my payment processor. I then store the response on the transaction the execution ends.  
LinvioIncLinvioInc
Well, only if you don't care what the results of the call are afterward :-)
Célio XavierCélio Xavier
Incredible @Ulas Kutuk, I had this same problem in this call called RestAPI receiving "Read Timed Out" in most requests, I was already thinking about a more complex flow using a "Trigger" to not let the user save the record and he would redo the process, really it would not be the best solution. But you helped me a lot after several tests I didn't get the message "Read Timed Out". Many thanks and hugs from the developers in Brazil.