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
Manos SpanoudakisManos Spanoudakis 

Trigger Exception SELF_REFERENCE_FROM_TRIGGER

Hi All,

 

I am getting the following Exception from a trigger that was till now functioning with no problem !

 

The trigger is a very simple one, deleting AccountShares when an Account_Team record is deleted...

 

I am getting the SELF_REFERENCE_FROM_TRIGGER exception and I really cannot understand why...

Any help would be really appreciated !

 

The debug log is the one I am getting when I try to delete one Account_Team record.

=============================

trigger trgAccount_Team_Before_Delete on Account_Team__c (before delete) {
      
        Set<ID> sAccId=new Set<ID>();
      Set<ID> sUId=new Set<ID>();
      for(Account_Team__c at:trigger.old){
        if (at.ftxt_AccOwnerID__c==at.User__c) continue;
        sAccId.add(at.Account__c);
        sUId.add(at.User__c);
      }
      ClsAccount_Team.syncDeletedAccountSharing(sAccId,sUId);
}

 

 

//----ClsAccount_Team.syncDeletedAccountSharing Code-----

    public static void syncDeletedAccountSharing(Set<ID> sAccId,Set<ID> sUId){
        delete [Select Id From AccountShare Where UserOrGroupId In: sUId And AccountId In: sAccId AND RowCause='Manual'];
    }

 

======DEBUG LOG=========

 

16.0 APEX_CODE,DEBUG;APEX_PROFILING,INFO;CALLOUT,INFO;DB,INFO;VALIDATION,INFO;WORKFLOW,INFO 10:38:15.291|EXECUTION_STARTED 10:38:15.291|CODE_UNIT_STARTED|[EXTERNAL]|TRIGGERS 10:38:15.291|CODE_UNIT_STARTED|[EXTERNAL]|01q200000000Fyi|trgAccount_Team_Before_Delete on Account_Team trigger event BeforeDelete for [a0G2000000Q1Z5R]

 

10:38:15.292|METHOD_ENTRY|[8]|SET.add(ANY) 10:38:15.292|METHOD_EXIT|[8]|SET.add(ANY) 10:38:15.292|METHOD_ENTRY|[9]|SET.add(ANY) 10:38:15.292|METHOD_EXIT|[9]|SET.add(ANY) 10:38:15.292|METHOD_ENTRY|[11]|01p20000000DuDc|ClsAccount_Team.syncDeletedAccountSharing(SET, SET) 10:38:15.293|SOQL_EXECUTE_BEGIN|[94]|Aggregations:0|Select Id From AccountShare Where UserOrGroupId In: sUId And AccountId In: sAccId AND RowCause='Manual'

 

10:38:15.415|SOQL_EXECUTE_END|[94]|Rows:1 10:38:15.415|DML_BEGIN|[94]|Op:Delete|Type:AccountShare|Rows:1

10:38:17.040|DML_END|[94]

10:38:17.041|EXCEPTION_THROWN|[94]|System.DmlException: Delete failed. First exception on row 0 with id 00r2000002JUOctAAH; first error: SELF_REFERENCE_FROM_TRIGGER, Object (id = a0G2000000Q1Z5R) is currently in trigger trgAccount_Team_Before_Delete, therefore it cannot recursively delete itself: [] 10:38:17.042|METHOD_EXIT|[11]|ClsAccount_Team.syncDeletedAccountSharing(SET, SET)

 

10:38:17.042|FATAL_ERROR|System.DmlException: Delete failed. First exception on row 0 with id 00r2000002JUOctAAH; first error: SELF_REFERENCE_FROM_TRIGGER, Object (id = a0G2000000Q1Z5R) is currently in trigger trgAccount_Team_Before_Delete, therefore it cannot recursively delete itself: [] Class.ClsAccount_Team.syncDeletedAccountSharing: line 94, column 3 Trigger.trgAccount_Team_Before_Delete: line 11, column 7

 

10:38:17.042|CUMULATIVE_LIMIT_USAGE 10:38:17.042|LIMIT_USAGE_FOR_NS|(default)| Number of SOQL queries: 1 out of 20 Number of query rows: 1 out of 1000 Number of SOSL queries: 0 out of 0 Number of DML statements: 1 out of 20 Number of DML rows: 1 out of 100 Number of script statements: 7 out of 10200 Maximum heap size: 0 out of 3000000 Number of callouts: 0 out of 10 Number of Email Invocations: 0 out of 10 Number of fields describes: 0 out of 100 Number of record type describes: 0 out of 100 Number of child relationships describes: 0 out of 100 Number of picklist describes: 0 out of 100 Number of future calls: 0 out of 10 Number of find similar calls: 0 out of 0 Number of System.runAs() invocations: 0 out of 20 10:38:17.042|CUMULATIVE_LIMIT_USAGE_END 10:38:17.042|CODE_UNIT_FINISHED|trgAccount_Team_Before_Delete on Account_Team trigger event BeforeDelete for [a0G2000000Q1Z5R]

dmchengdmcheng

Do you have a trigger on the AccountShare object that is trying to delete Account Teams?

Manos SpanoudakisManos Spanoudakis

Hi dmcheng,

 

Many thanx for your reply, I don't have a trigger on AccountShare.

If there was any other trigger firing I would expect it in the debug log right ? The debug log I attached above is all I get

 

Cheers,

Manos

BomanBoman

Please provide details of your Account_Team__c object. Looks like it is in a Master-Detail relationship with AccountShare?

 

The only reason deleting an AccountShare would trigger the "before delete" on Account_Team__c would be because of cascaded deletes.

Manos SpanoudakisManos Spanoudakis

Hi Boman,

 

Thnx for your reply :)

 

There is no relationship between AccountShare and the Account_Team__c

 

The object's custom fields are described below

 

Edit | Del 
Account__cMaster-Detail(Account)  
Edit | Del 
DeletionFlag__cCheckbox 
Edit | Del | Replace 
Division__cPicklist 
Edit | Del 
External_ID__cText(44) (External ID) (Unique Case Insensitive)  
Edit | Del 
ftxt_AccOwnerID__cFormula (Text) This formula references multiple= 
Edit | Del 
ftxt_IsUserActive__cFormula (Text) This formula references multiple= 
Edit | Del 
Organisation__cLookup(Organisation) 
Edit | Del | Replace 
Sales_Channel__cPicklist 
Edit | Del 
SalesRole_ID__cText(50) (External ID) 
Edit | Del | Replace 
SalesRole_Type__cPicklist  
Edit | Del 
User__cLookup(User) 

 

 

Cheers,

M

 

 

BomanBoman

You have Account_Team__c as the "detail" in a M-D relationship with Account. Can you change this to a Lookup (1:n) and try?

Manos SpanoudakisManos Spanoudakis

Hi Boman,

 

Well since Account_Team__c is in the detail part of the relationship I wouldn't expect any issue right ?

Anyway this has been working fine till one week ago...

 

Cheers,

Manos

dmchengdmcheng

I'm stumped.  Have you tried putting the delete line directly in the trigger?  Also I think you should check for a null result on your Select Id From AccountShare ... before you perform the delete - I don't know what happens when you try to execute a DML statement on a null list.