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
Sravan R PinnintiSravan R Pinninti 

What is ideal for referencing the value of a foirmula field in Triggers. Before or After??

HI,

I have a scenario where I have to assign the ownership of child records based on the value of a formula field on the parent record. I have used before Insert and it seems the functionality is working as expected but I have some concern over the order of execution.
Can someone suggest me the Ideal way of doing this. Should I go for a before trigger or After Trigger?
justin_sfdcjustin_sfdc

Hi Sravan,

In my view, it should be an after trigger because once you insert/update the parent record, then only it should change the ownership of the child record, right. You might also want to add after update in your trigger as per your requirement.

Thanks!

Himanshoo SethHimanshoo Seth
You can use it at both the places. The formula fields are updated as soon as the DB operation is done. So even in the before trigger if you refernce the formula field you will get the new value. So it all depends where you want to use it and for what. If you want to update some field based on formula field value then use it in before trigger and if you want to do some other operation which need your data to be saved in database then use the after trigger.