You need to sign in to do that
Don't have an account?
shan876
DML, 21.. my for loop please need assistance
Hi I have the following:
I keep geting
Too many DML statements: 21: Trigger.updateCM: line 25, column 17
What should I do...
Code:
trigger updateCM on Account_Membership__c (after update) { // first, we need to change the status of all case roles if the // CM status value has changes if (Trigger.isUpdate) { for (Integer i = 0; i < Trigger.new.size();i++) { Account_Membership__c casenew = Trigger.new[i]; Account_Membership__c caseold = Trigger.old[i]; // we check to see if the status has changed if (casenew.Status__c != caseold.Status__c) { for(Contact_Membership__c cr: [select Id, Account_Membership__c from Contact_Membership__c where Account_Membership__c = :casenew.id ]) { cr.Status__c = casenew.Status__c; cr.Type__c = casenew.Type__c; cr.Joined__c = casenew.Joined__c; cr.Expires__c = casenew.Expires__c; cr.OwnerId = casenew.OwnerId; update cr; } } } } }
Too many DML statements: 21: Trigger.updateCM: line 25, column 17
What should I do...
Hi,
First, just some remarks:
Then, try this:
Regards
adrian
Message Edited by modolea on 08-08-2008 01:23 AM
Message Edited by modolea on 08-08-2008 01:42 AM
Hi:
First I like to thank you...
second I tried the re-written trigger which I like...
but I get a different error for DML rows 126???
Error: Invalid Data.
Review all error messages below to correct your data.
Apex trigger updateCM caused an unexpected exception, contact your administrator: updateCM: execution of BeforeUpdate caused by: System.Exception: Too many DML rows: 126: Trigger.updateCM: line 30, column 9
Line 30 is update cmToUpdate;...
Is there a way around this?
Thanks
Hi,
You don't have to LIMIT your query, Execution Governors and Limits allows you to retrive 1,000 records. See "Understanding Execution Governors and Limits" in Apex Language Reference.
Avoiding runtime governor limits - alternative
Avoiding runtime governor limits - alternative 2
This is a helper class called by line 17 & 18
The idea is to use static class variables to store query results and process dml statements from two diferent triggers, one before update and other after update.
I hope this can help you.
regards
adrian
Message Edited by modolea on 08-08-2008 07:04 AM
Message Edited by modolea on 08-08-2008 07:05 AM
Message Edited by modolea on 08-08-2008 07:06 AM