You need to sign in to do that
Don't have an account?
What is causing my Cron job to get Too Many DML Rows error?
Here is my scheduled class and following it is the error I have gotten. This has been running for about a week now and I have received this error on two occasions. Basically it looks at a formula field and reassigns Accounts to the Owner's manager if the field states "YES". Can anyone provide a fix? Thank you!
global class AccountOwnerReassignCronJob implements Schedulable{ global void execute(SchedulableContext SC) { List <Account> acc = [Select OwnerId, Owner.ManagerId From Account Where Up_for_Reassignment__c ='YES']; for(Account a: acc){ if(a.Owner.ManagerId != null) a.OwnerId = a.Owner.ManagerId; } update(acc); } }
ERROR:
Apex script unhandled exception by user/organization: 00560000001L3AU/00D6000000077GT
Scheduled job 'Reassign Stagnant Accounts' threw unhandled exception.
caused by: System.LimitException: Too many DML rows: 10001
Class.AccountOwnerReassignCronJob.execute: line 9, column 1
This is the schedulable class
This will be your batch class.
Schedulable class will call the batch class and batch class will do what you want to do.
All Answers
You can process only 10000 Records in a DML Statment.
so you might be updating more than 10000 records.
Does this mean there is nothing I can do about it to allow the processing of more than those records?
This is the schedulable class
This will be your batch class.
Schedulable class will call the batch class and batch class will do what you want to do.
I attempted to save the first class and received this error: Error: Compile Error: Invalid type: AssignOwner at line 5 column 35
I attempted to create the second class and received this error: Error: Compile Error: AssignOwner: Class must implement the global interface method: void finish(Database.BatchableContext) from Database.Batchable<SObject> at line 1 column 14
I have edited the class. Try it.
Try to save the second class first and then the first class.
Code saved successfully and is loaded into Production now. I will know if it truly works in the morning.
Thank you!