Sub topic 8
Formula Size and Relationship Limits
This chapter assumes you can create a formula field in Object Manager and understand how lookup relationships connect objects. It covers the limits you hit as formulas grow, and how to resolve each one.
The three limits that matter
Salesforce checks a formula against several limits when you save it. Three of them cause most errors.
| Limit | Value | What it counts |
|---|---|---|
| Compiled size | 5,000 bytes | The formula after Salesforce expands field references and functions |
| Formula text length | 3,900 characters | The text you type, including spaces and comments |
| Relationship depth | 10 unique relationships | Each hop across a lookup or master-detail field |
The compiled size limit is the one that surprises people. A short formula can still exceed it, because each field reference expands internally. A reference such as Account.Owner.Name is stored as a chain of relationship lookups, and that chain takes far more space than the 18 characters you typed.
How relationship traversal counts
A cross-object formula follows lookup fields using dot notation. Each distinct hop counts toward the depth limit. Salesforce allows up to 10 unique relationships in one formula, and the formula can reach up to five levels of parent records.
Account.Owner.Manager.NameThis reads Opportunity to Account (hop 1), Account to Owner (hop 2), Owner to Manager (hop 3), then the Name field. The formula can only move from child to parent. It cannot read child records, which is why roll-ups exist.
Reducing formula size
When you see "Compiled formula is too big to execute" or "Formula is too long", apply these steps in order.
- Split the formula into two or more helper formula fields, then reference those fields from a final formula. Each helper has its own size budget.
- Replace nested
IFstatements withCASEwhen you compare one field to several fixed values. - Remove repeated sub-expressions. If
BLANKVALUE(Amount, 0)appears four times, compute it once in a helper field. - Shorten relationship chains. Copy a frequently used parent value into a field on the child, or use a Flow to maintain it.
Splitting has a cost. Helper formulas still count toward the object's formula field total, and a field referenced by other formulas cannot be deleted until those references are removed.
Exercise
A formula on Opportunity saves successfully in a sandbox but fails with "Compiled formula is too big to execute" after you add one more Account.Owner.Name reference. Why can adding a short reference cause this, and what is the first fix to try?
Show answer
Each relationship reference expands during compilation, so a short piece of text can add many bytes to the compiled size, which is capped at 5,000 bytes. The first fix is to move part of the logic into a helper formula field and reference that field, so each formula has its own size budget.