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
Surinder Singh 25Surinder Singh 25 

Too Many DML 10001 Error

I am getting too many DML 10001 error while updating a account record.
For that Account record their are more than 2000 contact records.
Please suggest some solutions for this issue.
 for (Contact c : [SELECT Id,accountId,Mailing_Street_1__c,Mailing_City__c,Mailing_Country__c,Mailing_State_Province_US_CA_Only__c,Mailing_Zonex__c ,Account.Physical_Street_1__c,Account.Physical_City__c,
                          FROM contact WHERE accountId in :acctsWithNewAddresses.keySet()]) 
            Account parentAccount = acctsWithNewAddresses.get(c.accountId);
            // Access the "old" record by its ID in oldmapAccount
            Account oldacc = oldmapAccount.get(parentAccount.Id);
            if(c.Mailing_Street_1__c == oldacc.Physical_Street_1__c && c.Mailing_City__c == oldacc.Physical_City__c &&  
               c.Mailing_Country__c == oldacc.Physical_Country__c && c.Mailing_State_Province_US_CA_Only__c == oldacc.Physical_State_Province_US_CA_Only__c)
                c.Mailing_County_Province__c = parentAccount.Physical_County_Province__c;
                c.Mailing_Street_1__c = parentAccount.Physical_Street_1__c;
                c.Mailing_Street_2__c = parentAccount.Physical_Street_2__c;
                c.Mailing_City__c = parentAccount.Physical_City__c;
                c.Mailing_Zip_Postal_Code__c = parentAccount.Physical_Zip_Postal_Code__c;
                c.Mailing_Country__c = parentAccount.Physical_Country__c;
                c.Mailing_State_Province_US_CA_Only__c = parentAccount.Physical_State_Province_US_CA_Only__c;           
        update updatedContacts;
Surinder Singh 25Surinder Singh 25
Error is for that particuar Account. No of related contacts for that account is 16000. Please ignore above count. As per my understanding, limit of DML processing in one txn is 10000. So how can i remove this.
Varun SinghVarun Singh
Hii @Surinder Singh 25
you can use limit or use batch apex
List<Thing__c> things = [select id from thing__c where status__c = 'Old value' limit 10000]; for (Thing__c thing : things) {
// make changes thing.status__c = 'New Value'; }
update things;


We can use Batch apex for these kinda problems. Please refer the below link for details

Hope it helps. Thanks
Surinder Singh 25Surinder Singh 25
Hi Varun,

Thanks for quick response.

But, we have around 16k contact records for that account, by using limit in SOQL i can process first batch of 10k and update the list. How will i process the remaining records.