Loading

Why the 'SELF_REFERENCE_FROM_TRIGGER' error occurs from Apex triggers

Julkaisupäivä: Aug 13, 2024
Kuvaus

 

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.

 

Ratkaisu

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-artikkelin numero

000385060

 
Ladataan
Salesforce Help | Article