
This is what I have:
global class FutureCallout
{
@TestVisible private static final Integer MAX_TRIES = 8;
@future(callout=true)
public static void generateCongaDocument(Id opportunityId, Id attachParentId, String sessionId, Integer tries) {
Http http = new Http();
HttpRequest request = new HttpRequest();
request.setEndpoint(CongaDocumentCreator.getCongaUrl(opportunityId, true, true, true, sessionId, attachParentId));
request.setMethod('GET');
request.setTimeout(120000);
HttpResponse response;
if ( !Test.isRunningTest() ) {
response = http.send(request);
} else {
response = new HttpResponse();
response.setStatusCode(200);
}
// Handle erraneous responses
if (response.getStatusCode() == 504) {
if ( tries <= MAX_TRIES && !InstallmentCreator.isAttachmentPresent(attachParentId) ) {
FutureCallout.generateCongaDocument(opportunityId, attachParentId, sessionId, ++tries);
}
} else if ( response.getStatusCode() != 200 ) {
ArcUtil.sendAdminNotification('Document Creation with Barcode for Installment ' + attachParentId + ' failed with HTTP Response Code ' + response.getStatusCode() +
'. Use the developer console to try creation again. Additional Info:\n\n---\n\nStatus:\n' + response.getStatus() + '\nBody:\n' + response.getBody() +
'\n\nRequest:\n' + request.getEndpoint());
}
}
}
Is there any way to do so? Can I schedule a job somehow and pass the job information to be processed?
Hi Roger,Try by creating another method which is not future and from that method call your future method. The method you created will be called whenever status code is 504.Please try the below code hope it will help.
Thanks,Amit.global class FutureCallout
{
@TestVisible private static final Integer MAX_TRIES = 8;
@future(callout=true)
public static void generateCongaDocument(Id opportunityId, Id attachParentId, String sessionId, Integer tries) {
Http http = new Http();
HttpRequest request = new HttpRequest();
request.setEndpoint(CongaDocumentCreator.getCongaUrl(opportunityId, true, true, true, sessionId, attachParentId));
request.setMethod('GET');
request.setTimeout(120000);
HttpResponse response;
if ( !Test.isRunningTest() ) {
response = http.send(request);
} else {
response = new HttpResponse();
response.setStatusCode(200);
}
// Handle erraneous responses
if (response.getStatusCode() == 504) {
if ( tries <= MAX_TRIES && !InstallmentCreator.isAttachmentPresent(attachParentId) ) {
FutureCallout.Callfuture(opportunityId, attachParentId, sessionId, ++tries);
}
} else if ( response.getStatusCode() != 200 ) {
ArcUtil.sendAdminNotification('Document Creation with Barcode for Installment ' + attachParentId + ' failed with HTTP Response Code ' + response.getStatusCode() +
'. Use the developer console to try creation again. Additional Info:\n\n---\n\nStatus:\n' + response.getStatus() + '\nBody:\n' + response.getBody() +
'\n\nRequest:\n' + request.getEndpoint());
}
}
public static void Callfuture(Id opportunityId, Id attachParentId, String sessionId, Integer tries){
FutureCallout.generateCongaDocument(opportunityId, attachParentId, sessionId, ++tries);
}
}