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

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,
Account.Physical_Country__c,Account.UGS_Zone_Ownership__c,Account.Physical_State_Province_US_CA_Only__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;
updatedContacts.add(c);
}
}
update updatedContacts;
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,
Account.Physical_Country__c,Account.UGS_Zone_Ownership__c,Account.Physical_State_Province_US_CA_Only__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;
updatedContacts.add(c);
}
}
update updatedContacts;
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;
OR
We can use Batch apex for these kinda problems. Please refer the below link for details
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_batch_interface.htm
Hope it helps. Thanks
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.