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
SFDC coderSFDC coder 

Error:Read timeout Exception during apex callouts

Hi all,

I have an apex callouts class taht invokes an external webservice.We have been using the SOAP API.
So i have imported the wsdl in salesforce and trying to invoke the autogenerated apex class.
However i get an error as:Read timeout Exception

Then i try to set the timeout as under and then invoke the webservice as below:
public class OrderCallOuts
{

    @future(callout=true)
    public static void sendOrders(String orderId)
    {
      try
      {
          
          //creating stub
          SfdcDirectordersinbound.MIOS_SFDC_DIRECT_ORDERPort  createOrder=new  SfdcDirectordersinbound.MIOS_SFDC_DIRECT_ORDERPort();
        
          //declaring the response element
          String callOutResponse='';
       
           // providing the credentials and setting the header
           createOrder.inputHttpHeaders_x=new Map<String,String>();
           String username = 'salerep1';
           String password = 'Pass_1235';  
           Blob headerValue = Blob.valueOf(username+':'+password);
           String authorizationHeader = 'Basic ' +EncodingUtil.base64Encode(headerValue);
           createOrder.inputHttpHeaders_x.put('Authorization',authorizationHeader);

          //setting the timeout           
          createOrder.timeout_x=120000;
           
          //Invoking the webservice to send orders from Salesforce  
          callOutResponse=createOrder.MIOS_SFDC_DIRECT_ORDER(myOrder.CreatedBy.name,myOrder.LastModifiedBy.name);
                                                
          System.debug('Response from SAP system:'+callOutResponse);
     }
     catch(Exception ex)
     {
         System.debug('*** Error'+ex);
     }     
    }
    
}


After executing the above code i get the below error:
*** ErrorSystem.CalloutException: Web service callout failed: WebService returned a SOAP Fault: Server Error faultcode=SOAP:Server faultactor=

Can anyone please help?

Thanks
Best Answer chosen by SFDC coder
Balaji Chowdary GarapatiBalaji Chowdary Garapati
@SFDC Coder:

Hi,
  Since you set the maximum time out, salesforce will wait 120K milli seconds for the result to be returned by the service that you were consuming. Since that service is not able to return in time, you were being timed out. This has nothing to do with Salesforce side service rather i would recommend checking with the person who published the service to see if he can imporve his codes  performance so that the output will be returned before the timeout happens.

 I have been through this issue before mainly with .net services which we consumed, their queries/store procs were taking too long to be run, after too much back and forth, the developer for that .net service accepted and tweaked his queries which improved the response time and it never got errored out later that.

Hope this helps:

Thanks,
balaji

All Answers

Balaji Chowdary GarapatiBalaji Chowdary Garapati
@SFDC Coder:

Hi,
  Since you set the maximum time out, salesforce will wait 120K milli seconds for the result to be returned by the service that you were consuming. Since that service is not able to return in time, you were being timed out. This has nothing to do with Salesforce side service rather i would recommend checking with the person who published the service to see if he can imporve his codes  performance so that the output will be returned before the timeout happens.

 I have been through this issue before mainly with .net services which we consumed, their queries/store procs were taking too long to be run, after too much back and forth, the developer for that .net service accepted and tweaked his queries which improved the response time and it never got errored out later that.

Hope this helps:

Thanks,
balaji
This was selected as the best answer
SFDC coderSFDC coder
thanks balaji...its exactly what was going wrong in our case as well...they did some modifications at their end and now its working.. :)
Satish PrajapatSatish Prajapat
Hello All,
Please refer the below code:
 
​HttpRequest req = new HttpRequest();
req.setEndpoint('Your url which you want to hit.');
req.setMethod('POST');
req.setBody('Body');//When I added this tag than I removed the 'read time out error.'
HttpResponse response = new Http().send(req);

Enjoy my DOST...!!!!!
Moin AhamadMoin Ahamad

Hi,
I'm facing the same issue and I tried hitting the end-point from Postman and its working fine but when I try hitting the same endpoint from Salesforce using Apex then it throws an exception for "Read Time out".

Please help me in getting this fixed.
Thanks

Kujambal Rajendran 23Kujambal Rajendran 23
Hi,
I'm facing the same issue and I tried hitting the end-point from Postman and browser and its working fine but when I try hitting the same endpoint from Salesforce using Apex and HTTP callout in flow, then it throws an exception for "Read Time out". I have set the maximum timeout as 120000 and set the body also. Appreciate your quick response in advance.