You need to sign in to do that
Don't have an account?
nickwick76
Too many DML rows
Hi,
When the SOQL-query in the code below returns more than 100 records I get following error message:
System.LimitException: Too many DML rows: 184
public void rollupAccountLocationUpdate(List accountLocations) { // Rollup updates to account locations to the opportunity line item "Last Modified Date" field List<OpportunityLineItem> opportunityLineItemsToUpdate = new List<OpportunityLineItem>(); for (OpportunityLineItem opportunityLineItem : [Select Id From OpportunityLineItem Where Account_Location__c In : accountLocations]) { opportunityLineItem.Last_Modified_Date__c = system.now(); opportunityLineItemsToUpdate.add(opportunityLineItem); } Database.SaveResult[] results = Database.update(opportunityLineItemsToUpdate, false); }
As I understand it, the update command should be able to take 1000 records.
This class is called by a trigger. Could that be the reason?
Ideas and suggestions are welcome!
BR / Niklas
You can update a max of 100 DML rows per transaction(assuming you have 1 record). This value scales with the number of records that needs to be updated.
If you have 2 records that needs to be updated, max DML rows limit would be 200.
Example:
If you are trying to update, assume 1 record of "Account_Location__c" that has 184 child items, it throws "Max DML rows " error.
Because you can only update 100 DML rows per transaction.
(In your case, i believe 1 account_location__c has 184 line items).
Best way to overcome this is by using "@future" annotation on your class that can allow upto 10,000.
Hope this helps.
Sales4ce
All Answers
In a single transaction upto 100 DML statements can be issued.
Even though the way you are doing is not as per the best practices, but the code should for work fine.
Can you let me know, is this particular method being invoked from another method?
It is being invoked from a trigger:
Rgds / Niklas
Trigger has different limitations.
Your code should be as below
Let me know if you face any issues.
Also, i will recommend you to go through the Governor limits in Apex documentation
Thanks, but it's the same problem.
It complains on the Database.update row as before.
// Niklas
In the controller code, can you make sure you have this parameter
public void rollupAccountLocationUpdate(Account_Location__c[] accountLocations) {
instead of this
public void rollupAccountLocationUpdate(List accountLocations) {
You can update a max of 100 DML rows per transaction(assuming you have 1 record). This value scales with the number of records that needs to be updated.
If you have 2 records that needs to be updated, max DML rows limit would be 200.
Example:
If you are trying to update, assume 1 record of "Account_Location__c" that has 184 child items, it throws "Max DML rows " error.
Because you can only update 100 DML rows per transaction.
(In your case, i believe 1 account_location__c has 184 line items).
Best way to overcome this is by using "@future" annotation on your class that can allow upto 10,000.
Hope this helps.
Sales4ce
Thanks!
Got it now! I thought the limit was regarding the number of update calls.
The annotation @future is probably what I need. I saw that the method has to be static though so it requires some changes, but that should be possible to fix.
// Niklas