You need to sign in to do that
Don't have an account?
Too many callouts with Apex Batch
Hi,
I wrote an apex batch which helps to delete reports in the Public Folder that haven't been run for more than 60 days.
When I test it in the Dev Console, I get an error such as "Too many callouts: 101".
How can I improve the code to overcome this issue?
Thanks for the help.
I wrote an apex batch which helps to delete reports in the Public Folder that haven't been run for more than 60 days.
When I test it in the Dev Console, I get an error such as "Too many callouts: 101".
How can I improve the code to overcome this issue?
Thanks for the help.
global class DeleteOldReportsBatch implements Database.Batchable<sObject>, Database.AllowsCallouts { //Get the records to be deleted global Database.QueryLocator start(Database.BatchableContext BC) { String query = 'select id, FolderName from Report where LastRunDate <= LAST_N_DAYS:60'; return Database.getQueryLocator(query); } //Executes the deletion logic for reports records global void execute(Database.BatchableContext BC, List<Report> scope) { String url; for(Report r : scope) { if (r.FolderName == 'Public Reports'){ Http h = new Http(); url = '/services/data/v44.0/analytics/reports/' + r.Id; System.debug(LoggingLevel.INFO, '*** url: ' + url); HttpRequest req = new HttpRequest(); req.setHeader('Authorization', 'Bearer '+ UserInfo.getSessionId()); req.setMethod('DELETE'); req.setEndpoint(url); HttpResponse res = h.send(req); System.debug(LoggingLevel.INFO, '*** rest: ' + res.getBody()); } } } global void finish(Database.BatchableContext BC) {} }
You need to update your Scheduler code : Used this code it will work fine.
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks,
Ajay Dubedi
All Answers
You need to update your Scheduler code : Used this code it will work fine.
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks,
Ajay Dubedi
I developer console try reducing the batch size to 100.
Id batchId = Database.executeBatch(new DeleteOldReportsBatch(), 100);
ref. https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_gov_limits.htm
Mark it as best answer if it helped.
It works fine now!