5

Assume we have ObjectA__c with Field1__c and ObjectB__c with formula field Field2__c which is formula to ObjectA__r.Field1__c.

I expected change of record field Field1__c of ObjectA__c would cause trigger on ObjectB__c to fire with changed Field2__c field, but this doesn't happen.

Can anyone explain why? Alternatively, can anyone share link to docs where is behavior is explained?

1
  • Solution is to trigger from your other object and verify if your logic needs to be executed. Feb 19, 2014 at 15:33

2 Answers 2

19

Basically, formula doesn't store any value. Formula is executed only when you retrieve it - use show this field on VF page or use formula field for your calculations in Apex code.

A formula is similar to an equation that is executed at run time.

An Introduction to Formulas

3
  • If you want to trigger some calculations for all objects which will be affected by changing field of ObjectA, I assume it will be needed to implement some complex logic. If you can tell us what exactly you want to achieve, maybe we might help you with it. Feb 19, 2014 at 12:26
  • My question was why it doesn't fire trigger. So, if a value of equation is changed then this should fire trigger on object where this value has been changed. Mentioned docs link just describes formula usage, however, unfortunately, doesn't contain answer to my question.
    – Patlatus
    Feb 19, 2014 at 12:52
  • 5
    I believe it does answer your question. The reason it doesn't fire is because the value is not stored. It is merely calculated at runtime. If the value isn't stored, then there is no DML operation to change it. Triggers only fire on DML operations. Feb 19, 2014 at 12:58
7

I believe the value of a formula field is not stored in the database, and does thus not change as you would expected.

The formula itself it stored, and when the field is queried, the formula is executed to calculate the formula value, which is then returned or displayed.

2
  • 2
    this is my understanding as well, but couldnt find documentation as such. Still looking Feb 19, 2014 at 11:39
  • Never Mind, looks like @Chiz found it. Feb 19, 2014 at 11:40

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .