function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Ramesh SomalagariRamesh Somalagari 

System.DmlException: Delete failed. First exception on row 0 with id

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.
Ankit AroraAnkit Arora
What I can predict is, there is a difference in data between sandbox and production. On Sandbox "bidline.size()" must be 0 so it doesn't try to delete it. But your code is not correct as you are trying to delete the Bid__c records in same trigger. Either try using furture method to delete them.
Ramesh SomalagariRamesh Somalagari
Sorry,Trigger on Bid__c  Object not  Bid_line__c Object .I try to delete the Bid_line__c object rows not an Bid__c Object.
Ankit AroraAnkit Arora
Then they must be in a master-detail relationship. And when you try changing the child record it updates the parent (and parent is in trigger context)
Ramesh SomalagariRamesh Somalagari
Yes Bid_line__c Object is  master-detail relationship with Bid__c  Object.So can please tell me solution why this error is came
Ramesh SomalagariRamesh Somalagari
 Master  Bid__c  Object have one field Roll-Up Summary (COUNT Bid_ line__c) are using in Production may be it is an issue.pleas tell me.