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

scheduled apex class getting Too many DML rows: 10001 error
So with the help of a few forums i found out you can schedule classes. So i created one that will check a box on a custom object at 5am daily. But when i went to check this morning on the job it failed due to the error: Too many DML rows: 10001
Below is the code used, which probably needs to be bulk-i-fied but each way i try it errors out. Any help is greatly appreciated.
Below is the code used, which probably needs to be bulk-i-fied but each way i try it errors out. Any help is greatly appreciated.
global class WineClubCronJob implements Schedulable{ global void execute(SchedulableContext SC) { List <Wineclub_Membership__c> acc = [Select Id, Tenure_Cron_Job_Schedule__c From Wineclub_Membership__c Where Active__c=True]; for(Wineclub_Membership__c a: acc ){ if(a.Tenure_Cron_Job_Schedule__c = False ) a.Tenure_Cron_Job_Schedule__c = True; } update(acc); } }
NOTE :- At a time you can do DML on 10K Record only.
Please mark this as solution if this will resolve you issue.
Thanks
Amit Chaudhary
amit.salesforce21@gmail.com
After that you can create on scheduler class to schedule above batch job.
Now above code can handler numbers of records.
Please check below post for more information on batch job
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_batch_interface.htm
1) If the start method of the batch class returns a QueryLocator, the optional scope parameter of Database.executeBatch can have a maximum value of 2,000. If set to a higher value, Salesforce chunks the records returned by the QueryLocator into smaller batches of up to 2,000 records. If the start method of the batch class returns an iterable, the scope parameter value has no upper limit; however, if you use a very high number, you may run into other limits.
2) If no size is specified with the optional scope parameter of Database.executeBatch, Salesforce chunks the records returned by the start method into batches of 200, and then passes each batch to the execute method. Apex governor limits are reset for each execution of execute.
Please mark this as solution if this will help you.
Thanks
Amit Chaudhary