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
RajaMohanRajaMohan 

How to resolve the Too many DML statements: 151 error??

hi folks,

 

I have written a trigger and caling a class from that. It is working fine for new records. If I use data loader then It is throwing me the followig error.

 

Too many DML statements: 151

 

How to resolve this error??

 

Thanks

Raj

Best Answer chosen by Admin (Salesforce Developers) 
JohanLiljegrenJohanLiljegren

Hi Raj,

 

Most likely, you're performing a SOQL statement within a loop, while looping through the records in the Trigger.

This works fine for single record updates, but you'll get into trouble when doing bulk updates/uploads through the API.

 

For more info on how to avoid this anti-pattern, see e.g. http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_patterns_bulk.htm

 

Hope this helps.

All Answers

JohanLiljegrenJohanLiljegren

Hi Raj,

 

Most likely, you're performing a SOQL statement within a loop, while looping through the records in the Trigger.

This works fine for single record updates, but you'll get into trouble when doing bulk updates/uploads through the API.

 

For more info on how to avoid this anti-pattern, see e.g. http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_patterns_bulk.htm

 

Hope this helps.

This was selected as the best answer
RajaMohanRajaMohan

Hi Johan

 

Thanks for your reply.

 

Now I am gettign the following error,

 

Error:Method does not exist or incorrect signature:List<Attribute_Reminder__c>.keySet()

 

Will you please elobrate how to resolve this?

 

Here I am writing the trigge in after insert, after update and calling a class to create a group of records.

 

Thanks

Raj