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

System.Exception: Too many DML rows:
Hi All,
I am updating opportunities while updating the Account Owner.
Opportunities are more than 100 , so i divided into batches of 50
but i am still getting the DML execption while updating 300 records ( max DML satatements should be 6)
\Error: Apex trigger PAMUpdate caused an unexpected exception, contact your administrator: PAMUpdate: execution of BeforeUpdate caused by: System.Exception: Too many DML rows: 147: Trigger.PAMUpdate: line 63, column 5
Here is my complete snipped of code
trigger PAMUpdate on Account (before update) {
Map <Id, String> acc = new Map <Id, String>();
List<String> accountList = new List<String>();
for (Account a : Trigger.new)
{
String oppOwner = Trigger.oldMap.get(a.Id).OwnerId;
if (a.IsPartner == true && a.OwnerId != oppOwner)
{
accountList.add(a.Id);
}
}
// System.debug(' Accounts are ' + accountList );
// System.debug(' Account Size is = ' + accountList.size() );
List<Opportunity> oppList = new List<Opportunity>();
if(accountList.size()>0)
{
oppList = [select PAM__c,PartnerAccountId from Opportunity
where PartnerAccountId In : accountList limit 300];
}
for(Opportunity oppRec:oppList)
{
oppRec.PAM__c = Trigger.newMap.get(oppRec.PartnerAccountId).OwnerId;
}
if(oppList.size() > 50){
List<Opportunity> subList = new List<Opportunity>();
for(Opportunity record : oppList){
subList.add(record);
if(subList.size()==49){
try{
update subList; }
catch(Exception ex){
System.debug(' Exception Occured' + ex);}
subList.clear();
}
}
if(subList.size() > 0){
try{
update subList; }
catch(Exception ex){
System.debug(' Exception Occured' + ex);}
}
}else{
try{
update oppList; }
catch(Exception ex){
System.debug(' Exception Occured' + ex);}
} }
Please suggest if i am doing any thing wrong while updating .
Thanks in advance
i am use the batches of 50 so can't i upadte the record upto 300 with 6 batches of 50 ( as it will include on 6 DML statements) . As per my understanding i can update 100 records in 1 batch.
XactiumBen is correct, if your trigger sees one record you can perform DML on a maxiumum of 100 rows - regardless of how many DML statements you use to process the records. If the cardinality of your data is not suited to fit within this scope you have a couple of options.
You can start using Async apex to process larger chunks but if the data could be reasonably unbounded you should investigate Batch Apex.
Andrew, Actually problem is that i have more than 1000 opportunities to update. I was just giving a trial with 300. If trigger has limit to update 100 DML at a time , so can't we create batches of 100 ( Beacuse the DML Statement limit is 20) . so with that we can update 100 *20 = 20,000 records.
Please suggest
Yeah it happns frequently and we need some automation...........
Any other solution??
http://www.mkpartners.com/blog/apex-code/so-many-dml-rows-so-few-dml-statements
Hope this url will solve this problem.