You need to sign in to do that
Don't have an account?
ssoftware
System.LimitException: ads:Too many DML statements: 151
Hi All,
List<CronTrigger> lstJobs = [SELECT Id FROM CronTrigger WHERE CronJobDetail.Name LIKE '%myReports%'];
for(CronTrigger ct : lstJobs) system.abortJob(ct.Id);
I run the above code on a daily basis to clean up some old scheduled batch jobs, and I am getting the limitexception:
System.LimitException: ads:Too many DML statements: 151
I undestand that bulkifying the above would solve the issue - similar to other DML operations on standard and custom objects.
My question is - how to do bulkify this operation? Is there a way to mass delete schduled jobs as abortJob() function seems to take only one Job Id at a time?
Kind Regards
Madhav
List<CronTrigger> lstJobs = [SELECT Id FROM CronTrigger WHERE CronJobDetail.Name LIKE '%myReports%'];
for(CronTrigger ct : lstJobs) system.abortJob(ct.Id);
I run the above code on a daily basis to clean up some old scheduled batch jobs, and I am getting the limitexception:
System.LimitException: ads:Too many DML statements: 151
I undestand that bulkifying the above would solve the issue - similar to other DML operations on standard and custom objects.
My question is - how to do bulkify this operation? Is there a way to mass delete schduled jobs as abortJob() function seems to take only one Job Id at a time?
Kind Regards
Madhav
I haven't tryied myself but, have you tried something like...
And to make the first call
Regards
[And remember, if it helps, mark it as "Best Answer", if not ... reply ;) ]
All Answers
I haven't tryied myself but, have you tried something like...
And to make the first call
Regards
[And remember, if it helps, mark it as "Best Answer", if not ... reply ;) ]
Thank you for your quick reply. I appreciate it. Using @future is an interesting idea and I will check it out to see if it helps. My suspicion is that it will not because in the future function, you are still looping through for each job and then aborting the job (so 1 DML for each job id). Thus it is not really bulkifying the DML statements into one mass delete DML statement.
I also see that the code is using a counter which limits the process to under 150 to avoid the limit exception.
I have tested the following code similarly, and it works due to the LIMIT:
List<CronTrigger> lstJobs = [SELECT Id FROM CronTrigger WHERE CronJobDetail.Name LIKE '%myReports%' LIMIT 50];
for(CronTrigger ct : lstJobs) system.abortJob(ct.Id);
However I am not very happy with this solution, as it looks like a workaround. But it seems like this is probably the only way for the time being.
Thanks for your input again. I appreciate it.
Kind Regards
Madhav