3

I'm trying to implement an auto-retry method on callout fail.

I notice that is better to wait some prudential time to make the retry call, to avoid flooding issues on remote server.

By now, I'm thinking on implement a schedulable interface to retry using something like this:

try {
    //Execute web service call here     
    HTTPResponse res = http.send(req);  

} catch(System.CalloutException e) {
    //Exception handling goes here.... retry the call
    //instance an schedulable class
}  

Questions:

Is it possible to instance a scheaduble class and schedule that job to N minutes after exception was cath?

What could be the best approach to give retryClass the number of attemps already executed? using SchedulableContext ?

Is there any other workarround ?

  • Where is this code sitting? Batch, Controller? – Boris Bachovski Aug 7 '13 at 22:59
  • This code is called on a future method from a trigger. – Martin Borthiry Aug 8 '13 at 12:19
2

I would suggest that you can insert the failed record Id into a separate custom object and also stamp the time your batch started .Then when your batch finishes you can schedule the job on the custom object to pick the inserted records due to failed transaction and remember to mark a check box or delete from the custom object if the transaction succeeded .

Caution:There are limits on no of scheduled jobs at a time .

  • Thanks Mohith, but I don't get how can I schedule the job N minutes after Now() ? – Martin Borthiry Aug 8 '13 at 12:24
  • 1
    DateTime dtnow = system.now(); String schTime = '0 ' + (dtnow.minute()+1) + ' ' + dtnow.hour() + ' ' + dtnow.day() + ' ' + dtnow.month() + ' ? ' + dtnow.year(); System.schedule('Scheduled Job Name', schTime, new YOURSCHEDULABLECLASSNAME()); – Boris Bachovski Aug 9 '13 at 1:42
0

I know this is an old post but I was dealing with the same issue. It turned out to be nasty little issue and since I could not find a satisfactory solution I have build a little generic framework which I put on Github. I hope this will help others.

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.