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
NikeNike 

Error: Too many DML rows: 10001

Hello,

Here, Iam copying the campaign members to its parent campaign but its fail on bulk insert.

below are the Code:

Awaiting for your suggestions.

trigger RollupParentCampaign on CampaignMember (After insert, After update) {
    
    List<CampaignMember> lstcampmembercreate = new List<CampaignMember>();    
    List<CampaignMember> lstchildcamp = new List<CampaignMember>();
    Set<Id> setCampaignId = new Set<Id>();  
    
    for(CampaignMember irow: Trigger.new)
    {   
        if(irow.ParentCampaignId__c != null && irow.ReollupCampaignMember__c == 'True')
        {
            setCampaignId.add(irow.CampaignId);    
        }
    }    
    
    if(setCampaignId != null)
    {
        lstchildcamp = [Select Id,ParentCampaignId__c,CampaignId,ContactId,LeadId,Status
            from CampaignMember where CampaignId IN:setCampaignId];       
    }
                        
    for(CampaignMember childcamp : lstchildcamp)    // Retrieve the list of childcampaign members     
    {        
        CampaignMember newcampmemb = new CampaignMember();        
        newcampmemb.CampaignId = childcamp.ParentCampaignId__c;
        newcampmemb.Status = childcamp.Status;
    
        if(childcamp.LeadId != null)
        {
            newcampmemb.LeadId = childcamp.LeadId;
        }
    
        else if(childcamp.ContactId != null)
        {
            newcampmemb.ContactId = childcamp.ContactId;
        }        
    
        lstcampmembercreate.add(newcampmemb);    
    }

    if(lstcampmembercreate.size() > 0)
    {
        try {
        
        database.insert(lstcampmembercreate,false);    // move childcampaignmembers to parantcampaign members
        
        }
        catch (Exception e)
        {
            System.assertEquals('Error: ', e.getMessage());
        }
    }         
}

Thanks
Best Answer chosen by Admin (Salesforce Developers) 
kiranmutturukiranmutturu

 

Best way to overcome this is by using "@future" annotation using a class 

You can update a max of 150 DML rows per transaction(assuming you have 1 record). This value scales with the number of records that needs to be updated.

 

 

Example:

 

If you are trying to update, assume  1 record of "CampaignMember"  that has 184 child items, it throws "Max DML rows " error.

Because you can only update 150 DML rows per transaction.

(In your case, i believe 1 CampaignMember has 184 line items).

 

All Answers

Rahul SharmaRahul Sharma

Trigger seems to be proper,

Check if there's any other trigger are invoked.

NikeNike

Thank you, Rahul

 

The "CampaignMember" object carries only one trigger.

 

any alternative method to avoid it?

 

Thanks

 

 

Ankit AroraAnkit Arora

Seems problem is here :

 

if(lstcampmembercreate.size() > 0)
    {
        try {
        
        database.insert(lstcampmembercreate,false);    // move childcampaignmembers to parantcampaign members
        
        }
        catch (Exception e)
        {
            System.assertEquals('Error: ', e.getMessage());
        }
    }

 Make sure that "lstcampmembercreate" doesn't contain more than 10000 record which will be inserted.

 

Thanks

Ankit Arora

Blog | Facebook | Blog Page

kiranmutturukiranmutturu

 

Best way to overcome this is by using "@future" annotation using a class 

You can update a max of 150 DML rows per transaction(assuming you have 1 record). This value scales with the number of records that needs to be updated.

 

 

Example:

 

If you are trying to update, assume  1 record of "CampaignMember"  that has 184 child items, it throws "Max DML rows " error.

Because you can only update 150 DML rows per transaction.

(In your case, i believe 1 CampaignMember has 184 line items).

 

This was selected as the best answer
Shashikant SharmaShashikant Sharma

I think you need to filter this query more as it is returning more than 10000 records that satisfies condition to be updated in the trigger.

 

[Select Id,ParentCampaignId__c,CampaignId,ContactId,LeadId,Status
            from CampaignMember where CampaignId IN:setCampaignId]; 

 

Ankit AroraAnkit Arora

Ohh great!! Nice to see cross post and so many are live to provide help.

 

Thanks

Ankit Arora

Blog | Facebook | Blog Page

kiranmutturukiranmutturu

@ankit.. we are always ready to help as fast as we can but they are not that much fast to accept the solutions... some times they even didn't check later on....but what ever happens providing the soutions is what we all can do... Thank you...

Ankit AroraAnkit Arora

That should not matter to you. We are here to provide best solutions/answers.

 

Thanks

Ankit Arora

Blog | Facebook | Blog Page

NikeNike

Kiran, I just reviewing all you suggestion, have to understand and implement then only i could come to an decision.

 

I really love your quick reply. I strongly belive " words that others may benefit with the soluction or any comments.

 

Thanks

 

 

kiranmutturukiranmutturu

hey nike... the post is not for you actually,...just we are exchanging the words.. sorry if i trouble you... 

NikeNike

No, I don't mind.

 

Happy family!

ArunaAruna

Hello,

 

I am also having same kind of problem , when I am trying to update contact and account in a trigger i am getting "Too many DML rows: 10001"

 

Here is bleow Trigger  , please suggestme how to solve this problem

 

and one more don't worry about  "'012E0000000PQBrIAO'; these id's i  will change those later.

trigger

UpdateOpportunityTrigger onOpportunity (beforeupdate) {

 

String ACCOUNT_RECORD_TYPE_OWNER =

'012E0000000PQBrIAO';

String ACCOUNT_ACTIVE_TYPE =

'Active Contact';

 

String CONTACT_RECORD_TYPE_CUSTOMER =

'012E0000000PQC3IAO';

String CONTACT_STATUS =

'Active';

 

set<Id> OppAccountIdSet=newset<Id>();

 

list<Account> accountUpdate=newlist<Account>();

 

for(Opportunity opp : Trigger.new){

OppAccountIdSet.add(opp.AccountId);

}

list<Account> accountList = [SELECT ID, RecordTypeID, Type from ACCOUNT where ID IN: OppAccountIdSet];

 

set<Id> OppContactIdSet=newset<Id>();

 

list<Contact> contactUpdate=newlist<Contact>();

 

for(Opportunity opp : Trigger.new){

OppContactIdSet.add(opp.Principal_Owner__c);

}

list<Contact> contactList = [SELECT ID, RecordTypeID, Contact_Status__c from CONTACT where ID IN: OppContactIdSet];

 

for ( Opportunity opp : Trigger.new){

 

if (opp.StageName == 'Closed Won') {

 

try{

 

for(Accountacc : accountList){

acc.recordTypeId = ACCOUNT_RECORD_TYPE_OWNER;

acc.Type = ACCOUNT_ACTIVE_TYPE;

accountUpdate.add(acc);

}

update accountUpdate;--> Here I am getting " Too many DML rows: 10001" 

for(Contactcon : contactList){

con.RecordTypeId = CONTACT_RECORD_TYPE_CUSTOMER;

con.Contact_Status__c = CONTACT_STATUS;

contactUpdate.add(con);

}

updatecontactUpdate;Here I am getting " Too many DML rows: 10001" 

}

catch(Exception e ){

 

}

}

 

 

}

 

}