When I get an error on some of my @future methods and would like to dynamically rerun the records that have failed at a later stage or have a list of records that failed and click rerun button to rerun the original transaction.
Is there any way I can rerun a failed Apex Async Job?
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Unfortunately the answer is no, nor does Salesforce retain the information to do so I suspect. If you want to implement retry/recovery logic you will have to build this in yourself.
Using Batch Apex lends itself to this more easily since it drives most of its state from the records in your objects. Thus enabling you to implement some kind of status on such objects that allow your users to review and retry failed records more easily (perhaps via a List View filter and button).
Implementing Batch Apex or @future requires more consideration than is first apparent, when you consider failures, both of a system level and validation logic due to data errors. I’ve tried to capture some of the considerations I tend to keep in mind in this blog post.