4

I'm trying to make future callout from an Apex trigger to POST to an external webservice URL but getting a Read Time Out error.

Here are the issues:

  1. Why is the JSON not forming from the serialize method?
  2. Why does the setout time method not work?
  3. Why am I able to call from external applications like PostMan but not from Salesforce?
  4. Is there any workaround for this? Because if successful for next time getting a duplicate data error.

HTTP Class:

public static void IntegrationOppupdate(id opptyid) {
//Construct HTTP request and response
    //Http request method,Endpoint and setBody
    HttpRequest req = new HttpRequest();
    req.setHeader('Content-Type','application/json');
    String endpoint = 'https:TEST.COM';
    req.setMethod('POST');
    req.setEndpoint(endpoint); 
    req.setTimeout(2 * 60 * 1000);
    system.debug('Opportunity ID' +opptyid);
    //SOQL to construct JSON string in set body
    Opportunity Op=[select id,Name,Stagename,Integration_Type__c,Account.Name,Admin_Contact__r.Name,Admin_Contact__r.Phone,Admin_Contact__r.Email from opportunity where stagename='Closed-Won' and id=:opptyid];
    system.debug('without pretty'+JSON.serialize(Op));
    String JsonString=JSON.serialize(Op);
    req.setBody(JsonString);
    system.debug(JsonString);
    //Http response method 
    Http http = new Http();
    HTTPResponse res = http.send(req);
    System.debug(res.getBody());
1
  • The Endppoint written is correct? It seems really strange. It isn't a valid URL
    – murcix
    Feb 5, 2017 at 22:57

1 Answer 1

9

We can't increase the timeout more than 120 sec since that is the maximum limit. The only workaround is to modify the query on the external webservice application to respond within 120 secs. Its suggestible to test the HTTP url from any on the REST applications like POSTMAN before making a decision in salesforce.

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .