1

This question already has an answer here:

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?

marked as duplicate by Eric, Ratan Paul, cropredy, Sebastian Kessel, Keith C apex Sep 11 '16 at 10:11

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • Please, share your trigger code so we can see what you've attempted, and why it doesn't work as expected. – smukov Sep 10 '16 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. – Srujan Sep 10 '16 at 9:10
  • a formula field update on it's own is not enough, you need a DML action with it. – Girbot Sep 10 '16 at 9:18
5

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.

  • So you want me to replace formula field with trigger ? – Srujan Sep 10 '16 at 9:25
  • No, leave the formula field on Tournee, but you can't use a trigger on that object. You need to create a trigger on Opportunity instead. Then, inside the Opportunity trigger you need to do your thing that you are currently trying to achieve in Tournee trigger. – smukov Sep 10 '16 at 9:28
  • 2
    The key thing to understand is that trigger on Tournee object won't be fired when a Date field on Opportunity is updated, because formula fields do not cause a trigger to be fired. You need to use the Opportunity trigger instead to get the related Tournee records and then perform the required logic on them. – smukov Sep 10 '16 at 9:39

Not the answer you're looking for? Browse other questions tagged or ask your own question.