3

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.

7
  • 3
    Its strange that it is working in Sandbox but if you look in debug log the trigger is calling recursively. Can you plz chk if there is any rollup summary field or any workflow field update? Jul 11, 2014 at 4:24
  • 2
    Use AFTER UPDATE trigger instead. DELETE will turn on the isDeleted flag to 'true` which is an update to the object. Then it's self reference. Better to use AFTER UPDATE trigger context
    – highfive
    Jul 11, 2014 at 4:44
  • Hi @ highfive Can you tell me where I should use the isDeleted flag to 'true'. Okie can I try AFTER UPDATE it is works right?. Please let me know.
    – Ramesh S
    Jul 11, 2014 at 4:54
  • Are you sure the API versions of the triggers are the same on the sandbox as on the production environment? Jul 11, 2014 at 7:05
  • Yes both Sandbox and Production API versions are same for the trigger.
    – Ramesh S
    Jul 11, 2014 at 7:27

1 Answer 1

-1

Change your trigger to After Update.

2
  • 2
    Don't know if you realize it or not, but that answer was given in the comments by @tandonprateek along with his reasons as to why; something you've not provided in yours.
    – crmprogdev
    Jul 11, 2014 at 15:24
  • 1
    This definitely needs some more information!
    – Matt Lacey
    Jul 12, 2014 at 3:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.