3

I have trigger it working in Sandbox.It delete the records when the field "Delete__c" check box is checked.I have tested 200 rows,Trigger deleted rows in sandbox but the same scenario in production their are using apex data-loader update Bid__c Object with 250 records.Each Bid__c have 4 to 7 Bid_line__c that means my trigger can delete the 1300+ rows approximately .See the following code for trigger,It working in GUI.Can someone please tell me why it is not delete the records in Production?

Code:

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)                
                DELETE bidline; 
        }
     }
     CATCH(EXCEPTION E){
         SYSTEM.DEBUG('ERROR:'+E);
     }   
} 

Yes,I have Debug in Production I got a 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)
  • What is the error in your debug log? – Boris Bachovski Jul 8 '14 at 6:02
  • 1
    BTW, you only need the try block around the DML (DELETE) statement. – Nick Cook Jul 8 '14 at 6:44
  • Can I use the Database.delete(bidline)?instated DELETE.Already try catch block are their. – Ramesh S Jul 8 '14 at 7:31
  • 1
    Do you have a trigger running on the Bid_Line__c object? Also, have you tried running this on an AFTER trigger? – Nick Cook Jul 11 '14 at 4:17
  • Trigger run on the Bid__c Object not Bid_Line__c object.Both are different objects with look up relationship.Why this error came.Okie can I try after insert it works right?. Please let me know. – Ramesh S Jul 11 '14 at 4:27
1

Your bidline SELECT statement is using the IDs of your Bid__c object.
i.e.

 ... WHERE Bidline__c IN :bidid ...

I'm assuming Bidline__c is not the lookup field to the Bid__c object.

Try updating the Bidline__c in this statement to whatever the lookup field is.

i.e.

...  WHERE Parent_Bid__c IN :bidid ....

Where Parent_Bid__c is the name of the lookup field.

  • I have edited in the notepad.I didn't see the select query.Now I edited the same select query can you please check and let me know – Ramesh S Jul 8 '14 at 6:38
  • Hi All I have edited the question can you please check – Ramesh S Jul 11 '14 at 3:43
  • 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? – tandonprateek Jul 11 '14 at 4:26
  • I have compare both Sandbox and Production Object's one of the Roll Up Summary field on the Bid__c Object but not in Sandbox. Now I have modified the Trigger AFTER UPDATE then it working as I accepted.Thank for ALL. – Ramesh S Jul 11 '14 at 14:18

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.