3

I want to call out my web service after the insert process of a custom object with a delay of 2 minutes. But i am getting that exception FATAL_ERROR|System.CalloutException: Read timed out How can i fix that problem ? Here is my implementation.

Callout class:

public class HttpCallout{
    @Future(callout=true)
    public static void getContent(String url){
        Http h = new Http();

        HttpRequest req = new HttpRequest();
        req.setEndpoint(url);
        req.setMethod('GET');
        req.setTimeout(2000);

        HttpResponse res = h.send(req);
        String response = EncodingUtil.urlDecode(res.getBody(),'UTF-8');
        System.debug('***response****'+response);
    }

    public void serviceCaller(){
        getContent(url);
    }
}

Trigger:

trigger AfterInsertOrUpdate on Sales_Order__c (after insert) {
    System.debug('Making future call to update account');
    HttpCallout httpCallout = new HttpCallout();
    httpCallout.serviceCaller();
    System.debug('After Insert');
}

Any help would be appriciated.

1 Answer 1

5

The argument to HttpRequest.setTimout is a millisecond value so for 2 minutes:

req.setTimeout(2 * 60 * 1000);

PS With the clarification that the desire is to make the web service call after a 2 minute delay I suggest you experiment with this Need System.schedule cron string for run once approach. In your case you would build the cron string to be 2 minutes from the current date/time.

7
  • I tried that but the web service has been called out just after the insert process. Commented Aug 8, 2014 at 13:09
  • @user3864408 Perhaps a better title for your question would be "How to schedule a web service call for 2 minutes in the future".
    – Keith C
    Commented Aug 8, 2014 at 13:11
  • Yes it is then how can i make it ? Commented Aug 8, 2014 at 13:19
  • @user3864408 See link in PS.
    – Keith C
    Commented Aug 8, 2014 at 13:21
  • i didnt understand anything from the link i think this is not what i am looking for Commented Aug 8, 2014 at 13:27

You must log in to answer this question.

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