You need to sign in to do that
Don't have an account?
Too many DML statments:21
I am getting the "too many dml statements" error when I do a bulk update. I realize that the problem is that I have an insert statement inside a for loop but I am unsure of how to resolve the issue. How do I get the fields I want to update into a map or list so that I can then update them all at once? I am confused about the syntax...Here is the portion of my code that is giving me a problem... thanks!!!!!
///Part 2 B update //if health, update the health market if (HealthGo) { for(Account a: accts){ a.Health_Market__c=Market; a.Health_Renewal_Date__c=RenewalDate; a.Health_Underwriter_Assigned__c = Underwriter; update accts; } } else{ } //if dental, update the dental market if (DentalGo) { for(Account a: accts){ a.Dental_Market__c=Market; a.Dental_Renewal_Date__c=RenewalDate; update accts; } }
All Answers
for(Account a: accts){ if (HealthGo) { a.Health_Market__c=Market; a.Health_Renewal_Date__c=RenewalDate; a.Health_Underwriter_Assigned__c = Underwriter; } else{ if (DentalGo) { a.Dental_Market__c=Market; a.Dental_Renewal_Date__c=RenewalDate; } } update accts; }
Are you sure that will update all of the accounts? I thought the for loop would allow me to "loop" through... I would think your proposed solution would only update the last one... ?
Thanks!
http://wiki.developerforce.com/index.php/Statements#Loops
it been my problem to:smileyvery-happy: