Hi All I have written the apex trigger.It working in sandbox but not in Production.While upload the csv file by using apex data loader in production it throws an exception below.
Exception:
31:04.975 (975279099)|EXCEPTION_THROWN|[29]|System.DmlException: Delete failed. First exception on row 0 with id a3O80000001pJnxxxx; first error: SELF_REFERENCE_FROM_TRIGGER, Object (id = a3N8000000aaaa) is currently in trigger Bidpro_Details_Delete, therefore it cannot recursively update itself: []
12:31:04.975 (975850995)|SYSTEM_METHOD_EXIT|[29]|Database.delete(LIST<SObject>)
12:31:04.975 (975925291)|SYSTEM_METHOD_ENTRY|[46]|String.valueOf(Object)
12:31:04.975 (975965515)|SYSTEM_METHOD_EXIT|[46]|String.valueOf(Object)
12:31:04.975 (975987895)|SYSTEM_METHOD_ENTRY|[46]|System.debug(ANY)
12:31:04.975 (975997242)|USER_DEBUG|[46]|DEBUG|ERROR : Trigger BidDeleteTrigger_Delete :System.DmlException: Delete failed. First exception on row 0 with id a3O80000001pJnxxxx; first error: SELF_REFERENCE_FROM_TRIGGER, Object (id = a3N8000000aaaa) is currently in trigger Delete, therefore it cannot recursively update itself: []
12:31:04.976 (976004076)|SYSTEM_METHOD_EXIT|[46]|System.debug(ANY)
Apex Trigger:
Trigger BidDeleteTrigger on Bid__c (BEFORE UPDATE)
{
TRY
{
LIST<Bid_line__c> bidline = NEW LIST<Bid_line__c>();
LIST<Id> bidid = NEW LIST<Id>();
FOR(Bid__c bidpro : Trigger.NEW)
{
IF(bidpro.Delete__c == TRUE)
{
bidpro.Delete__c = FALSE;
bidid.add(bidpro.Id);
}
}
IF(bidid.SIZE() != 0)
{
bidline = [SELECT ID FROM Bid_line__c WHERE Bid__c IN: bidid LIMIT 50000];
IF(bidline.size() != 0)
Database.DeleteResult[] del = Database.DELETE(bidline);
}
}
CATCH(EXCEPTION E){
SYSTEM.DEBUG('ERROR:'+E);
}
}
Same code is working in Sandbox.It not throws any exception.Can someone please help me.
AFTER UPDATE
trigger instead.DELETE
will turn on theisDeleted
flag to 'true` which is an update to the object. Then it's self reference. Better to useAFTER UPDATE
trigger context