Salesforce Formula Fields: Complete Guide
Quick Summary:
Formula fields automatically calculate a value based on other fields, always staying current without manual updates. No code required — just Salesforce's formula syntax.
What Is a Formula Field?
A formula field displays a value calculated from other fields on the record (or related records), recalculating automatically every time it's viewed. Unlike a regular field, you never manually enter a value — the formula determines it every time.
How to Create One
Go to the object's Fields & Relationships and click New.
Select Formula as the field type and choose the return type (Text, Number, Date, Checkbox, etc.).
Build the formula using the Advanced Formula editor, inserting field references and functions as needed.
Use the Check Syntax button to validate before saving.
Set field-level security and add to relevant page layouts.
A Real-World Example
A support team wants to see, at a glance, how many days a Case has been open. A formula field calculating TODAY() minus the Case's Created Date, displayed directly on the record and available in reports, replaces what would otherwise require someone to manually calculate this every time it's needed.
Simple Example Formula
IF( ISBLANK(Close_Date__c), TODAY() - CreatedDate, Close_Date__c - CreatedDate )
🚫 Common Mistake
Not handling null/blank values, causing #ERROR to display when a referenced field is empty. Wrapping potentially-blank fields with ISBLANK() or BLANKVALUE() checks prevents this from surfacing as a visible error to end users.
💡 Pro Tip
Keep formulas as simple as reasonably possible, and add comments (using /* */) for anything non-obvious — a complex formula with no explanation becomes genuinely difficult for anyone (including future you) to maintain months later.
Frequently Asked Questions
What\'s the maximum character length for a formula field?
Formula field definitions are limited to 5,000 characters compiled, and 3,900 characters in the raw formula editor — complex formulas can hit this limit and need to be simplified or split.
Can a formula field reference another formula field?
Yes, formula fields can reference other formula fields, though deeply nested chains can affect performance and make debugging harder.
Do formula fields update in real time?
Yes — formula fields recalculate automatically whenever the record is viewed or the underlying data changes; they're not stored values that need manual refreshing.
Can formula fields be used in reports and list view filters?
Yes, formula fields function like any other field for reporting and filtering purposes, once created.
Why can\'t I edit a formula field\'s value directly on a record?
Formula fields are read-only by design — their value is always calculated from the formula, never manually entered, which is what makes them reliable for derived data.
Can a formula field cross object relationships?
Yes, using cross-object formulas that traverse lookup or master-detail relationships (up to 10 levels), letting a formula reference fields on a related record.
Can formula fields perform date calculations?
Yes, formula fields commonly calculate things like days between two dates, age from a birthdate, or whether a deadline has passed, using built-in date functions.
Do formula fields count against custom field limits?
Yes, a formula field counts as a custom field toward your object's field limit, the same as any other field type.
Can I use IF and CASE logic in a formula field?
Yes, both IF() for simple conditional logic and CASE() for multi-branch logic are supported, letting formulas return different values based on conditions.
Why is my formula field showing #ERROR?
Usually caused by a division by zero, a null value being referenced in a way the formula doesn't handle, or a data type mismatch — wrapping potentially-null references with ISBLANK() checks often resolves this.