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
kittu9kittu9 

Getting Too Many DML Rows:10001 in trigger

trigger EstimateUpdateOnAccount1 on Estimates__c(after insert,after update)
{

 List<Account> accsToUpdate = new List<Account>(); 
              
for(Estimates__c EST : trigger.new)
{
 if( Trigger.isInsert)
 {
    if (est.year__c == '2012')
    {
    accsToUpdate.add(new Account(Id = EST.Account__c, Most_Recent_Estimate_Date__c =EST.Created_Date_Value__c, Estimate_Amount__c = EST.Estimate_Total_Fiscal__c ));
    
    }
    
    else
    
    
    {accsToUpdate.add(new Account(Id = EST.Account__c, Most_Recent_Estimate_Date_2__c =EST.Created_Date_Value__c, Estimate_Amount_2__c = EST.Estimate_Total_Fiscal__c ));
    }
    
    if (accsToUpdate != null && !accsToUpdate.isEmpty())
    Database.update(accsToUpdate);
 }
 
 if( Trigger.isUpdate)
 {
    if (est.year__c == '2012')
    {
    accsToUpdate.add(new Account(Id = EST.Account__c, Most_Recent_Estimate_Date__c =EST.Created_Date_Value__c, Estimate_Amount__c = EST.Estimate_Total_Fiscal__c ));
    
    }
    
    else
    
    
    {accsToUpdate.add(new Account(Id = EST.Account__c, Most_Recent_Estimate_Date_2__c =EST.Created_Date_Value__c, Estimate_Amount_2__c = EST.Estimate_Total_Fiscal__c ));
    }
    
    if (accsToUpdate != null && !accsToUpdate.isEmpty())
    Database.update(accsToUpdate);
 }
}
}

 

When am doing upsert operation through data loader. Am getting the following error like "Too Many DML Rows:10001"  can any one help me on this. why am getting this issue.wht mistake  i done in trigger. Please give inputs on this ASAP. thanks in advance

Naidu PothiniNaidu Pothini
trigger EstimateUpdateOnAccount1 on Estimates__c(after insert,after update)
{
    List<Account> accsToUpdate = new List<Account>(); 

    if((Trigger.isInsert || Trigger.isUpdate) && Trigger.isAfter)
    {
 	for(Estimates__c EST : trigger.new)
	{
   	    if (est.year__c == '2012')
	    {
		accsToUpdate.add(new Account(Id = EST.Account__c, Most_Recent_Estimate_Date__c =EST.Created_Date_Value__c, Estimate_Amount__c = EST.Estimate_Total_Fiscal__c ));
	    }
	    else
	    {
		accsToUpdate.add(new Account(Id = EST.Account__c, Most_Recent_Estimate_Date_2__c =EST.Created_Date_Value__c, Estimate_Amount_2__c = EST.Estimate_Total_Fiscal__c ));
	    }
	}

	if (accsToUpdate != null && !accsToUpdate.isEmpty())
	{
	    Database.update(accsToUpdate);
	}
    }
}

 try this.

Ranu JainRanu Jain

You are using Database.update(accsToUpdate) in for loop. Its giving too many SOQL exception.

Try to take all items in list and then update outside for loop.

kittu9kittu9
Could you please provide the changes in code. How to do it
Ranu JainRanu Jain
trigger EstimateUpdateOnAccount1 on Estimates__c(after insert,after update)
{

 List<Account> accsToUpdate = new List<Account>(); 
              
for(Estimates__c EST : trigger.new)
{
 if( Trigger.isInsert)
 {
    if (est.year__c == '2012')
    {
    accsToUpdate.add(new Account(Id = EST.Account__c, Most_Recent_Estimate_Date__c =EST.Created_Date_Value__c, Estimate_Amount__c = EST.Estimate_Total_Fiscal__c ));
    
    }
    
    else
    
    
    {accsToUpdate.add(new Account(Id = EST.Account__c, Most_Recent_Estimate_Date_2__c =EST.Created_Date_Value__c, Estimate_Amount_2__c = EST.Estimate_Total_Fiscal__c ));
    }
    //this DML is inside loop
    //if (accsToUpdate != null && !accsToUpdate.isEmpty())
    //Database.update(accsToUpdate);
 }
 
 if( Trigger.isUpdate)
 {
    if (est.year__c == '2012')
    {
    accsToUpdate.add(new Account(Id = EST.Account__c, Most_Recent_Estimate_Date__c =EST.Created_Date_Value__c, Estimate_Amount__c = EST.Estimate_Total_Fiscal__c ));
    
    }
    
    else
    
    
    {accsToUpdate.add(new Account(Id = EST.Account__c, Most_Recent_Estimate_Date_2__c =EST.Created_Date_Value__c, Estimate_Amount_2__c = EST.Estimate_Total_Fiscal__c ));
    }
    //this DML is inside loop
   // if (accsToUpdate != null && !accsToUpdate.isEmpty())
    //Database.update(accsToUpdate);
 }
}
// DML outside loop
 if (accsToUpdate != null && !accsToUpdate.isEmpty())
    Database.update(accsToUpdate);
	
}

 I just correct your code for showing DML out side for loop.  Although Update and Insert coditions also can be merged if the logic in same for both.

 

sfdcfoxsfdcfox
The error is TOO MANY DML ROWS. The problem wasn't specifically the DML inside a loop (but, it's good that that was fixed). The problem is in a different area of code. The problem with governor limits is that they often produce errors that are red herrings (false problems). In this case, the actual error so happened in this trigger, but the CAUSE of that error doesn't appear to be in this trigger at all. You will need to determine which of your triggers that are firing are causing the problem.