Loading

Why the 'SELF_REFERENCE_FROM_TRIGGER' error occurs from Apex triggers

게시 일자: Aug 13, 2024
상세 설명

 

SELF_REFERENCE_FROM_TRIGGER error from Apex indicates that you have attempted to update or delete a record that is already being updated by another trigger.

 

솔루션

Things to avoid in your code that can cause this issue:

Direct operations that cause Apex error

 

1. A trigger performs a DML operation that attempts to update a record that’s already being updated by another trigger. Read more about DML operations in our Developer Documentation.
2. Apex trigger causes a DML event to run on a record already involved in an identical DML event.

 

Example of indirect operation that causes Apex error


The Apex error you received can also be caused by an indirect operation that requests conflicting updates. Here’s an example of an indirect operation that can trigger the error message.
 

1. Request submitted to update Object A.
2. A before update trigger on Object A creates an Object B.
3. Object A is updated.
4. An after insert trigger on Object B queries Object A and updates it.


This is an indirect update of Object A because of the before trigger of Object A, so an error will be generated.

Read our Developer Documentation about Core Data Types Used in API to find out more information on potential error messages you can encounter with Apex.

Knowledge 기사 번호

000385060

 
로드 중
Salesforce Help | Article