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

Before trigger Vs After Trigger

Hi guys,

Recently I have came across very interesting scenario and I am now struggling to find the root cause of it.

Its related to Impact of Rollup summary fields on the execution of triggers.

Scenario : 
(Parent object --> X)
(Child object --> Y)
>>I have one rollup summary field on X doing Sum operation on one of Y field say 'Amount'.
>>Now I have updated my parent's record, and it execute the "before update" trigger of X.
>>In this trigger I am updating Opportunity records and in one of triggers defined on Opportunity I am updating the 'Amount' field of child object Y.

*So due to the rollup summary field it will again enforce to run the trigger of Parent object X and will throw the ERROR of "Self reference recursion"

*This behavior is expected but when I changed the trigger of X from "before update" to "after update" it resolve my issue, but how?

It seems like Salesforce do not like to update the field involved in Rollup summary field of parent before the data commit to database.

Please share your thoughts that why it fixed in after update event ?

Thanks --
Hi Monika,
Can you please share your code here.

Fahad Akhtar