You need to sign in to do that
Don't have an account?

How to retry the callout on http request timed out in rest apex callouts?
Below is the code. Can anyone tell how to implement retry logic when the 2 minutes http request get timed out.
public static void sendOptyInfo(Set <Id> oppIdSet) { try{ for (Opportunity opp: [SELECT id ,StageName, Account.Name from Opportunity where id in: oppIdSet]){ String jsonBody = JSON.serialize(new Wrapper(opp)); HttpRequest request = new HttpRequest(); HttpResponse response = new HttpResponse(); Http http = new Http(); Api_Request__c apiReq = new Api_Request__c(); apiReq.Opportunity__c = opp.id; apiReq.Stage_Name__c = opp.StageName; apiReq.Account_Name__c = opp.Account.Name; insert apiReq; request.setEndpoint(''); request.setHeader('Content-Type','application/json'); request.setMethod('GET'); request.setBody(jsonBody); request.setTimeout(120000); system.debug('opp json' +jsonBody); response = http.send(request); if (response.getStatusCode() == 200) { System.debug('Response-' + response); Object results = (Object) JSON.deserializeUntyped(response.getBody()); } } } catch(System.CalloutException e){ System.debug('Error-' + e.getMessage()); } }
Here is a sample code
NOTE: The code provided is an example. You'll need to review and make modifications for your organization.
Let me know if this helps, if it does, please mark this answer as best so that others facing the same issue will find this information useful. Thank you
Please find this article as it relates to the requirement.
https://salesforcebitsandbytes.com/how-to-retry-the-callout-3-times-on-http-requests-based-on-the-response-in-apex/