[SalesForce] Dynamically get result of a VF field’s formula, using Apex

How can I get the result of a formula ("field update"/"workflow rule"), in Apex, without hard-coding it?

There is a field whose value (calculated on upsert) is the formula result. I have dismissed inserting a new record or updating a dummy record to get the solution, because the complexity of the org would have unacceptable ripple effects.

To answer responses asking why… My Apex function is used by a visualforce page to dynamically display the formula result (as the user is typing, not during submission).

To answer responses directing to meta data… I need to be able to calculate the formula's result, not just access the formula's text.

Thank you very much in advance.

Best Answer

I do not think this is possible. My understanding is that formulas are always calculated when a record is retrieved so even if the field were available (say duplicated on the object in question) the value would not be accurate.

I think you will have to code a copy of the formula into your controller and have the controller do the calculation for you.

Related Topic