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
AkoAko 

Apex Job using Webservice Callouts - Retry on Failure?

Hello,

I had previously implemented webservices calls using the Outbound Messages system. The feature I liked about this was that if a webservice call failed for whatever reason, Salesforce would retry the call several times before giving up (visible from the "Outbound Messaging Delivery Status" screen).

 

For various reasons I have re-implemented my webservice calls in an Apex class. The call gets made via an Apex Trigger which calls an Apex Class function which does the actual webservice call.

 

Anyways, that is all working nicely, but I am wondering what happens if the call fails? I know you can see the status of calls in the "Apex Jobs" screen, but it doesn't seem to retry upon a failure. It's possible I'm not quite implementing things correctly, as I can see "Status" as "Failed", yet the "Failures" column always shows as 0. "Total Batches" and "Batches Processed" is always 0 as well. Is there maybe a step I'm missing, or do Ajax Jobs not work in the way that Outbound Messages do? Is there a way I can set things up so Salesforce would re-attempt an Ajax Job until the status is "Completed"?

 

Thanks!

-Jeff

forecast_is_cloudyforecast_is_cloudy

Jeff - the automatic retry feature is only available with Outbound Workflow messaging. If you're invoking the web service using Apex., you'll need to implement the rety logic yourself. Note that writing such rety login in Apex wouldn't be trivial. You presumably want to wait for a certain amount of time (like 5 mins) before attempting the retry. SInce there is no 'timer' functionality in Apex you'd have to come up with a more elaborate design for retying the web service callout every x mins. You may be able to do in with a combination of a time based workflow and Apex triggers, but it'll be complicated.

Sorry I don't have better news for you :(

AkoAko

Thanks for the answer. And I spent all that time getting the webservice call to work!

 

Using the Apex class seems much "neater" than the method I was using, but I am concerned about possible downtime for the webservice I am calling. May have to stick with Outbound Messages. Wish you could initiate an Outbound Message from an Apex Class! Any idea if that's planned for the future?