+ Start a Discussion
Divya GoelDivya Goel 

System.Exception: Too many DML rows: 101

Hi I have to update more then 100 records in my update call but the limit of the trigger is just to update only 100 records in a trigger. Please let me know how i can update more then 100 records in my trigger. Thanks Divya Prakash Goel
Best Answer chosen by Admin (Salesforce Developers) 
fgwarbfgwarb

I assume that the solution would be to test if your list object has more than 100 rows, and if it does break the primary list into sub lists then update the sub list... .something like:

 

 

if(fullList.size() > 100){

List<obj> subList = new List<obj>();

for(obj record : fullList){

subList.add(record);

if(subList.size()==99){

update subList;

subList.clear();

}

}

  if(subList.size() > 0){

udpate subList;

}else{

update fullList;

Message Edited by fgwarb on 07-27-2009 09:35 AM

All Answers

Vijay RautVijay Raut
Hi,
 
I am also having same requirements.
 
My trigger is also hitting the DML Rows limit.
 
If you able to do some work arround then please let me know.
 
Thanks in advance.
steel steelsteel steel
I have a master contract to child contract object relationship.  When the master is changed, the children must also be modified, but in sometimes very complicated ways.... hence the custom APEX trigger.  However, we have 100's of sub-contracts and the DML limit is preventing us from rolling out this product.

Help please!?

Thanks in advance.
Chirag MehtaChirag Mehta
Did anyone of u got any solution, request then to post it here ...
fgwarbfgwarb

I assume that the solution would be to test if your list object has more than 100 rows, and if it does break the primary list into sub lists then update the sub list... .something like:

 

 

if(fullList.size() > 100){

List<obj> subList = new List<obj>();

for(obj record : fullList){

subList.add(record);

if(subList.size()==99){

update subList;

subList.clear();

}

}

  if(subList.size() > 0){

udpate subList;

}else{

update fullList;

Message Edited by fgwarb on 07-27-2009 09:35 AM
This was selected as the best answer
TomCusack29TomCusack29

This is not the correct solution.

 

100 is the limit of DML records that can be process for each record that fires the trigger.

Breaking the list which is greater than 100 records into sublists will still hit the limits.

 

Example: The first sublist's DML will be fine as it is under 100 records but the second will fail as it goes over 100 records for the record that causes the trigger to fire! The limt is not refreshed after the first DML.

 

These limits scale with trigger batch size.

1 record to hit trigger, 100 DML records can be processed

2 records to hit trigger, 200 DML records can be processed

3 records to hit trigger, 300 DML records can be processed

etc, etc

 

Please test your code, the code breaks the list into sublists correctly but doesn't solve the problem being asked!
TomCusack29TomCusack29

I have resolved this problem by limiting the amount of records being returned by my SOQL query but another solution could be to look into Batch Apex. You can find more information about this in the Apex Code Developer's Guide.

 

Good luck!

feelsfdcfeelsfdc

Hi,

 

How I can overcome this issue in Batch Apex?  Any suggesstion.

 

Thanks.

 

 

magsy1.3942130065717605E12magsy1.3942130065717605E12
@TomCusack29 how did u limit the amount of records returned in SOQL  query. Could you please paste the code.
Thanks