4

Just for the sake of argument, if I had the following formula field:

MyObject__c.FormulaField__c = DAY(TODAY()) 

What is the actual value of this field stored in the database, will the value change the next day?

7

The answer to this question just got more interesting as of the Spring 13 release.

I would take a moment to read this recent blog post on large data volumes and custom indexes to get more details.

Essentially, as of Spring 13, it is possible to contact support and ask that a custom formula field be indexed, which, in that case, something must be stored in the database.

But this only is allowed for deterministic formulas. NOW and TODAY are called out quite explicitly as non-deterministic in nature.

So the answer is still "no". Formula field values with TODAY and NOW are not stored in the database, and will always be recalculated on record read. I just felt this was a great opportunity to draw attention to this new indexing feature.

6

Formula fields are not stored in the database they are calculated at query time. As a result they always have the correct value.

  • That's interesting; especially from an architectural perspective. I always thought, in an application, models would simply be direct mappings of database tables. I never thought models could be further "enhanced" at query time before being consumed by an application. Just out of curiosity, does this query-time calculation occur at the DB layer, or at the app layer? Is this what tools like hibernate provide? – Jan Julian Mar 27 '13 at 4:54
  • Its part of the translation from SOQL -> SQL. SOQL query gets parsed, formula fields get picked up on, and the formula which makes up the field is injected into the SQL query. – Phil Rymek Mar 27 '13 at 14:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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