function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
aishonlineaishonline 

Batch apex issue - Too many DML rows: 10001

Hi, I am getting an error while updating a list of records in Betch class execute method.

 

Code snippet is as below:

 

for(Activity_Product__c ActivityProduct: ActivityProductList){
            if(ActivityProduct.price_list__r.COGS_IMPACT_FLAG__c == 'Y')
            {
                 System.debug('11111111  First If Block');            
            }
            
            if(ActivityProduct.price_list__r.DP_IMPACT_FLAG__c == 'Y'){
                System.debug('222222222  second If Block');               
              }
            
            if(ActivityProduct.price_list__r.SR_IMPACT_FLAG__c == 'Y' ){
                System.debug('33333333  3rd If Block');         
            }
            
            if(ActivityProduct.price_list__r.COGS_IMPACT_FLAG__c == 'Y' || ActivityProduct.price_list__r.DP_IMPACT_FLAG__c == 'Y' || ActivityProduct.price_list__r.SR_IMPACT_FLAG__c == 'Y')
            ActivityToUpd.add(ActivityProduct);            
         
        }
               
        Database.update(ActivityToUpd,false);  // getting that error on this line.

 

Any help would be highly appreciated.

Thanks a lot.

Best Answer chosen by Admin (Salesforce Developers) 
sandeep@Salesforcesandeep@Salesforce

Hi for this you should keep in mind that list you are inserting should not  have items more than 10000. so while using batch process please keep your small batch size so in each batch more than 10000 record can not come in list to be inersted at a time. 

 

because this is salesforce limiation ( not to execute dml on more than 10000 item at once). so we should customize way of creating list. as one way I suggested above.

All Answers

sandeep@Salesforcesandeep@Salesforce

Hi for this you should keep in mind that list you are inserting should not  have items more than 10000. so while using batch process please keep your small batch size so in each batch more than 10000 record can not come in list to be inersted at a time. 

 

because this is salesforce limiation ( not to execute dml on more than 10000 item at once). so we should customize way of creating list. as one way I suggested above.

This was selected as the best answer
Suresh RaghuramSuresh Raghuram

Decrease the batch size.

 

provide complete code snippet.

Deepak Kumar ShyoranDeepak Kumar Shyoran

Hi Aishonline,

 

You getting this error because you are  crossing the limit of maximum number of records that can be process in a context which is 10,000 and in your case you surely cross the limit of processing maximum records in context.You need to limit the size of list to 10,000 on which you going to perform DML operation.Please let me know if there is any problem.

 

 

Don't forget to give Kudos if this post helped you.

 

Mark my answer as a solution to your question if it solve your problem.

 

 

 

Choudhary Deepak Shyoran

Salesforce Developer

sandeep@Salesforcesandeep@Salesforce

I think all are tuned with same concept of limiting smaller batch size to limt number of record in building a list (to perform "insert" DML) so please take your answer or let me know if you need any further query. 

Thanks

aishonlineaishonline

Thanks a lot guys 4 ur help.... i just decreased the size of scope that i was passing with the help of custom setting, and it worked.

 

Thnx 4 ur quick support...!!!!  :):)