+ Start a Discussion

Too Many DML Rows: 300


Using SOQL query in Trigger i am able to query 1000 records at a time. Since list is having the capacity of 100 records updation at a time, we are updating 1000 records using 10 different list (Dividing 100 records per list). At the time of updating it is accumulating the each list updates and giving error like 'Too Many DML Rows : 200 '. Why it is accumulating the all updates even after dividing into 10 different lists.
How to rectify this is error. Please do the needful ASAP.
Rajesh ShahRajesh Shah

Well the behaviour is correct. As per the Governor Limits, Total number of records processed as a result of DML statements is 100 for trigger.  What this means is that irrespective of the total number of DML statements (which cannot be more than 20) you have in your trigger, you can update a total of 100 records only. :(


The only way I know to increase the governor limits is to use @future annotation and call an apex class which would do the processing. Using @future would run it in a new context and the limit will increase to 10,000. 


Also do let us know if you find any better way to do this.




Can you post some code? You should be able to perform 20 DML operations of 100 records i.e. a trigger can handle up to 20 update/insert/upsert/deletes on lists of records up to a size of 100 records.


If you need to work with bigger sets of data the @future notation is the only way I know of(as mention by Rajesh).




Rajesh ShahRajesh Shah

I tried this simple trigger to test the DML limit



trigger DML_Operation_Test on Account (after update) { Contact[] conList = new List<Contact>(); for(Contact c : [Select Id, LastName from Contact where AccountId = :trigger.new[0].Id limit 1000]) { c.LastName = 'Updated Name'; conList.add(c); if(conList.size() == 100) { update conList; conList.clear(); } } }


 I was expecting this code to work for upto 1000 records. But it gave me an Too many DML rows 200. I checked the system log. The first update happened properly. But the second update gave the error. So as per this, I can to the conclusion that we can update only 100 records in total in a trigger.





This code and behaviour is expected.


However if you passed the trigger 20 accounts you would be able to process 2000 records i.e. if your trigger is on an object eg. Account and you perform some DML on objects related to an account your limit is 100 x the number of Accounts the trigger fired for.


I supposed it all depends how your data is being passed to the trigger.



Message Edited by wesnolte on 07-15-2009 03:35 AM
Rajesh ShahRajesh Shah

Thanks for clarifying that Wes.  So now as per my understanding, for triggers, the Total number of records retrieved by SOQL Queries and Total number of records processes as a result of DML statements scale as per the batch size. So if you are inserting or updating 10 records, following would be the governor limits:

Total number of records retrieved by SOQL Queries:  1000 * 10 = 10,000
Total number of records processed as a result of DML statements: 100 * 10 = 1,000

Also, since you can have only 20 DML statements per trigger and a list can hold only 1000 records, so the maximum number of records processed as a result of DML statements = 20,000. (Assuming the batch size to be 20 or more)


Let me know if I am wrong in this.


 Manohar, your trigger might be getting called only for a single record or for less than 10 records. Hence it is not updating the 1000 records. And there is no need to divide the list into 10 of size 100. You can update a list of 1000 records with a single DML statement. 

Message Edited by Rajesh Shah on 07-16-2009 03:51 PM

So, if my trigger is processing a single record, the max number of records that can be updated is 100, correct? And if I have > 100 records to process, is using the @future annotation the only other option?


Edit: Sorry, I probably need to be more specific than that :smileyhappy: My trigger is on the Account object and it fires when the address is updated in any given account. When the trigger fires, it should update the address of all the contacts that are associated with this account. For now, I'm setting this trigger up so that it only works for a single account update at a given time. What I failed to understand until now is that since my trigger will always contain one record, the max number of records that can be updated is 100. And the challenge I have is that there are accounts with way over 100 contacts. Is using the @future annotation my only option to process more than 100 records? If so, I imagine I'd have to somehow index the records so that I know which records have already been processed.


Any suggestions will greatly be appreciated. Thanks in advance.

Message Edited by J&A-Dev on 09-02-2009 08:37 AM
Message Edited by J&A-Dev on 09-02-2009 08:38 AM
Rajesh ShahRajesh Shah

As per my knowledge, @future is the only option.

Also, I am not sure why you are moving in the direction of indexing. I would pass the Account Id to the @future method and let it deal with all the contact update.