+ Start a Discussion
Vijay RautVijay Raut 

Too Many DML Rows

Hi,
 
According to Apex Document, Number of records processed as a result of DML statement (Number of DML Rows) is 100. But this limit scales with trigger batch size. Means if i pass 200 records in trigger then this limit will be 100 * 200 = 20,000.
 
Strange thing, It is working fine in case of the Insert DML statement but for delete DML Statement, it throws exception for Trigger batch of more than 100 records.
 
I have attached two trigger code. One is working properly (having insert DML) with batch more than 100. And another throwing exception (having Delete DML).
 
This Code Works Properly:
 
Code:
trigger MFD_Archive on Account (before delete) 
{
 try  
 {
  String MARK_FOR_DELETE_ADMIN = '005T0000000ifGGIAY';
  String BUSINESS_ACCOUNT_RECORDTYPEID = '01250000000DJZIAA4';
  
  for ( Account [] sourceAccounts : [Select Id, Name, MFD_OldOwnerId__c, OwnerId,
    RecordTypeId, MFD_IsArchived__c from Account
    where MFD_IsArchived__c = :false and Id IN :Trigger.oldMap.keyset()
    and RecordTypeId = :BUSINESS_ACCOUNT_RECORDTYPEID])
  {
   Account[] targetAccounts = sourceAccounts.deepClone(false);
   
   for(Integer i = 0; i<targetAccounts.size(); i++)
   {
    targetAccounts[i].MFD_SourceId__c = sourceAccounts[i].Id;
      targetAccounts[i].MFD_OldOwnerId__c = targetAccounts[i].OwnerId;
      targetAccounts[i].OwnerId = MARK_FOR_DELETE_ADMIN;
      targetAccounts[i].MFD_IsArchived__c = true;
   }
  
   insert targetAccounts;   
  
  }
    
    for ( Account [] sourceAccounts : [Select Id, FirstName, LastName, MFD_OldOwnerId__c, OwnerId,
      RecordTypeId, MFD_IsArchived__c from Account
      where MFD_IsArchived__c = :false and Id IN :Trigger.oldMap.keyset()
      and RecordTypeId != :BUSINESS_ACCOUNT_RECORDTYPEID])
  {
   Account[] targetAccounts = sourceAccounts.deepClone(false);
   
   for(Integer i = 0; i<targetAccounts.size(); i++)
   {
    targetAccounts[i].MFD_SourceId__c = sourceAccounts[i].Id;
      targetAccounts[i].MFD_OldOwnerId__c = targetAccounts[i].OwnerId;
      targetAccounts[i].OwnerId = MARK_FOR_DELETE_ADMIN;
      targetAccounts[i].MFD_IsArchived__c = true;
   }
  
   insert targetAccounts;   
  
  }
 }
 catch(Exception e)
 {
  // TODO - Log Error to Integration_Error__c object
   System.debug('Exception in MFD_Archive Trigger' + e.getMessage()); 
 }
}

 Following code throws Exception:
 
Code:
trigger MFD_Undelete on Account (after undelete) 
{
 try 
 {
  for ( Account[] archivedAccts : [select Id from Account
    where MFD_IsArchived__c = :true and MFD_SourceId__c IN :trigger.newMap.keyset()])
  {
   System.debug('Number of Archived Accounts ' + archivedAccts.size());
   
   if(archivedAccts.size()>0)
   {
    delete archivedAccts;
   }
  }
 }
 catch(Exception e)
 {
  System.debug('Exception in MFD_Undelete Trigger' + e.getMessage()); 
 }
}

 
Is anyone come accross this scenario? Or I am missing some thing in my code then please reply me.
 
Thanks in Advance.


Message Edited by Vijay Raut on 12-06-2007 10:50 AM
TehNrdTehNrd
I was under this same impression as well (2000 records) but then when I paid close attention to the worlding this is not correct.
 
Total number of DML statements issued: 20
Total number of records processed as a result of DML statements: 100
 
This means that regardless of the amount of statements you can only update 100 records. It is not 100 records per DML statement.
Vijay RautVijay Raut
Hi, Thanks for your reply.
 
But if you see the updated Apex document, its given as:
 
Total number of records processed as a result of DML statements: 100****
And the **** meaning, they have given this limit scales up with the batch size in trigger.
 
Let we assume that you are correct then, How does my insert statement in other trigger able to process more than 100 records?
 
Thanks.
TehNrdTehNrd
Didn't notice the ****. You are probably correct there.

When you delete an Account are you doing it from the UI? If so, this is only processing one record and you will only be able to delete 100 records. So if there are more than 100 Archived Accounts it will fail.
Vijay RautVijay Raut
Hmmmm ..... thanks.
 
Thats the problem. I was using Apex Data Loader for the Insert operation and undelete, i was doing from UI as i cant do it from Apex Data Loader.
 
But Why on UI, whole batch is assumed as only 1 record? Does it looks like something odd here?
 
Thanks.. Appreciate your help.
jyotijyoti

Vijay,

 

Can you explain how you were able to work around this on Insert?  We are running into the same issue on Update and are curious if we can employ the same tactic to get our update statement to work for more than 100 records.

Thanks.