In this post, we will talk about retrying the callout when receiving some defined responses like timeout error, internal server error etc. Usually, we should be prepared for these responses to accomplish the task expected after the callout smoothly.
You can approach this requirement using two apex classes .
To maintain the time interval between two callouts you can implement a Schedulable interface.
You can schedule the failure callout to retry after 5 minutes as continuous hitting can put your server flooded. (recommended)
And you are done, the below code gives a fair understanding of it.
Apex Class: RetryCallout
Apex Class: ScheduleCallout
For raw code , go to the git repo here
By implementing the Schedulable interface, we are leveraging the scheduling mechanism for failure callout that helps us in fulfilling our requirements.
Hope you find this post useful! Catch you in next content.
And thank you for being an awesome reader.
Share and grow together !!
If you have any doubts you can comment down below, I will try to reply ASAP.
Also keep visiting us, for more such content!