I have two objects called Opportunity and Tournee, with a date field and date field is a formula field which subtracts 10 days from date field in Opportunity and the trigger create events based on this dates and shows them in a calendar. Now, what I found is Tournee trigger is not being called on its date formula field update. Now how do i create Tournee events based on its date field?
-
Please, share your trigger code so we can see what you've attempted, and why it doesn't work as expected.– smukovSep 10, 2016 at 9:07
-
@smukov the code is too big with other functionalities, now all that i want is how to fire a trigger on Cross-Object Formula field update.– SrujanSep 10, 2016 at 9:10
-
a formula field update on it's own is not enough, you need a DML action with it.– GirbotSep 10, 2016 at 9:18
1 Answer
Formula fields aren't really being updated
per se, but instead, they are just evaluated when you perform a query against the record.
Because of this, if you have two objects A and B, and you have a cross-object formula field on object B that is referencing a field on object A. If you update a record A, you are probably expecting that the record B gets updated as well due to the cross-object formula field, however, this won't be the case. Instead, the record B will calculate the new formula value only when you query for the record, or simply open the record detail page.
Thus, if you want to fire a trigger
in this case on object B, the only option you have is to actually create a trigger
on object A, query for the related B records inside the object A's trigger
, and do whatever you need to do with those records.
-
-
No, leave the formula field on
Tournee
, but you can't use a trigger on that object. You need to create a trigger onOpportunity
instead. Then, inside theOpportunity
trigger you need to do your thing that you are currently trying to achieve inTournee
trigger.– smukovSep 10, 2016 at 9:28 -
2The key thing to understand is that trigger on
Tournee
object won't be fired when a Date field onOpportunity
is updated, because formula fields do not cause a trigger to be fired. You need to use theOpportunity
trigger instead to get the relatedTournee
records and then perform the required logic on them.– smukovSep 10, 2016 at 9:39