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
Sri 7Sri 7 

CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY:TriggerToUpdatePRPCInvoiceDisplayName: System.LimitException: Too many DML rows: 10001(please help me)

here it is class:

public class ZuoraProductRatePlanChargeTriggerHandler{

public static void UpdatePRPCIDNLineitems(map<Id,zqu__ProductRatePlanCharge__c> mapPRPC){

    Map<Id,Id> mapInvName = new Map<Id,Id>();
    List<Zuora__SubscriptionRatePlan__c> lstSub = new List<Zuora__SubscriptionRatePlan__c>();
       
    for(SPG_Product_User__c lstpc:[select id,Subscription__c,Rate_Plan_Charge__c from SPG_Product_User__c where Rate_Plan_Charge__c IN :mapPRPC.keyset() AND Subscription__c != Null])
    {
            mapInvName.put(lstpc.Subscription__c,lstpc.Rate_Plan_Charge__c);
    }
    
    for(Zuora__SubscriptionRatePlan__c lstsrp : [select id,PRPC_Invoice_Display_Name__c,Zuora__Subscription__c from Zuora__SubscriptionRatePlan__c where Zuora__Subscription__c IN :mapInvName.keyset()])
    {   
        Id IdVal =mapInvName.get(lstsrp.Zuora__Subscription__c);
        lstsrp.PRPC_Invoice_Display_Name__c = mapPRPC.get(IdVal).Invoice_Display_Name__c;
        
        lstSub.add(lstsrp);
    }     
                
   if(lstSub.size()>0)
        update lstSub ;   
    
 } 

}

Trigger:
trigger TriggerToUpdatePRPCInvoiceDisplayName on zqu__ProductRatePlanCharge__c(after insert, after update) 
{   
    if(Trigger.isAfter)
    {
        // Added this line as part of US#1168855
        if ((Trigger.isInsert || Trigger.isUpdate)&& (Test.isRunningTest() ||SPG_checkRecursive.runOnce()) ){
            ZuoraProductRatePlanChargeTriggerHandler.UpdatePRPCIDNLineitems(trigger.newmap);
        }
    }
    
}
Shivdeep KumarShivdeep Kumar
Hi,
You are facing this error because you are handling more than 10000 records in DML(Salesforce governor limit). so try to update the records by using Batch class or you have to use your SOQL with more filter criteria.

Thanks
Shivdeep
Sri 7Sri 7
Hi Shiva,

thanks for quick response.
 can you please help me on code or can you please send me code.

Thanks in advance
Khan AnasKhan Anas (Salesforce Developers) 
Hi,

Greetings to you!

The code is fine as you are not trying to update inside For loop.

System.LimitException: Too many DML rows: 10001 error occurs when we try to do DML operations to more than 10,000 records at a time.

If we want to do DML operations to more than 10,000 records at a time, we have to call a batch class from the current class to handle it separately.

It might possible that you have lots of child objects or update of these particular records causing lots of workflows or rollup recalculations to fire or recursion causing this error.

A recursive trigger is one that is called over and over. It can lead to the infinite loop and which can result to governor limit sometime. Sometimes it can also result in unexpected output. If not controlled will result in this error: maximum trigger depth exceeded. So we should write code in such a way that it does not result to recursion.

To avoid recursion we can use a public class static variable. As per the order of execution, all Before Trigger and After Trigger will fire before the workflow update. To prevent Trigger to be fired the second time, after workflow field update we can set a static boolean variable in a Class.

Create a static variable in a class as true. Make it false before or after a trigger has been executed. Variable will become false when trigger runs for the first time (before workflow update). If the variable is true only then trigger will fire and if the trigger will try to execute the second time then it will not fire.

Handler Class:
public class TestHandler{
     public static Boolean isTriggerExecuted = true;
}

Trigger:
trigger testTrigger on Account (after update){
     
    if(TestHandler.isTriggerExecuted){
         
        //Logic

        TestHandler.isTriggerExecuted = false;
    }
}

Or, you should really look into turning your trigger into the batch apex.

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks and Regards,
Khan Anas
Sri 7Sri 7
Hey Khan Anas,

thanks for response.
i tried this but it is not working for me so can you please help me in batch class or if it possible please paste the code here.

Thanks in advance.
 
Sri 7Sri 7
hi folks please help me on this