Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

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?

share|improve this question
    
Solution is to trigger from your other object and verify if your logic needs to be executed. –  Samuel De Rycke Feb 19 at 15:33
add comment

2 Answers

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

share|improve this answer
    
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. –  Chiz Feb 19 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 at 12:52
2  
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. –  sfdc_ninja Feb 19 at 12:58
add comment

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.

share|improve this answer
1  
this is my understanding as well, but couldnt find documentation as such. Still looking –  sfdc_ninja Feb 19 at 11:39
    
Never Mind, looks like @Chiz found it. –  sfdc_ninja Feb 19 at 11:40
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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