SELF_REFERENCE_FROM_TRIGGER: meaning and how to fix it

Apex runtime Checked against the official docs on Source: SOAP API Developer Guide: Core Data Types, StatusCode

Quick answer

SELF_REFERENCE_FROM_TRIGGER: A trigger updated or deleted the same record it is running for, in a way that is not allowed, such as updating the record from its own before trigger by DML. Start with: In a before trigger, set field values on Trigger.new directly instead of using DML.

Typical message: SELF_REFERENCE_FROM_TRIGGER, Object (id = 001...) is currently in trigger X, therefore it cannot recursively update itself

Cause

A trigger updated or deleted the same record it is running for, in a way that is not allowed, such as updating the record from its own before trigger by DML.

How to fix SELF_REFERENCE_FROM_TRIGGER

  1. In a before trigger, set field values on Trigger.new directly instead of using DML.
  2. Do not delete the triggering record from its own trigger.
  3. Use a static flag to guard against recursion if two triggers update each other.

Have a different message? Paste it into the error decoder, which matches it against 45 common Salesforce errors in your browser.

Frequently asked questions

What does SELF_REFERENCE_FROM_TRIGGER mean in Salesforce?

A trigger updated or deleted the same record it is running for, in a way that is not allowed, such as updating the record from its own before trigger by DML.

How do I fix SELF_REFERENCE_FROM_TRIGGER?

1. In a before trigger, set field values on Trigger.new directly instead of using DML. 2. Do not delete the triggering record from its own trigger. 3. Use a static flag to guard against recursion if two triggers update each other.

More Apex runtime errors

SFDX Talk is unofficial documentation. It is not affiliated with, endorsed by, or sponsored by Salesforce, Inc. Message text varies slightly by release and context, so confirm against the official page before relying on it.