You need to sign in to do that
Don't have an account?
Vijay Raut
Following code throws Exception:
Message Edited by Vijay Raut on 12-06-2007 10:50 AM
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
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,
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.