All articles

Platform

Compiled formula is too big: reduce Salesforce formula expansion

Distinguish formula character count from compiled size, simplify dependencies and decide when a stored calculation needs automation.

A short formula can fail the compiled-size check because it references other formulas. A helper field may shorten the editor text without reducing the expanded expression.

Salesforce’s formula limits reference distinguishes character count, saved size and compiled size. The current reference lists a 15,000-byte compiled limit; older troubleshooting pages may show earlier values. Use the error and current documentation for your org when diagnosing it.

Trace the dependency tree

List every formula referenced by the failing field, then follow their references. Look for an expensive expression included repeatedly through different branches. The visible text in the final field is only part of that calculation.

Removing whitespace can help a character-count problem, but it doesn’t reliably solve compiled expansion. Moving the same expression into another formula field can make the source easier to maintain while leaving the compilation problem intact.

Work on a copy in a sandbox. Change one part at a time and check the compiler’s result. Keep representative input-and-output examples so that a smaller formula doesn’t silently change the business rule.

Simplify the decision itself

Look for repeated conversions, duplicated conditions and branches that produce the same result. A CASE expression may make some mappings easier to read, but don’t assume a particular rewrite always compiles smaller. Measure it.

Review whether every condition is still required. A historical exception kept after its business process was retired adds complexity without protecting a current rule. Have the rule owner approve removal rather than deleting branches solely to fit the limit.

If the calculation is a large business mapping, consider whether configuration and automation express it more clearly. That changes the implementation and should include versioning, ownership and tests.

Understand the cost of storing the result

Replacing a formula with a stored field moves the responsibility for freshness into automation. Define every event that must recalculate it, including changes on related records, imports and time-dependent conditions.

A before-save flow can handle some same-record calculations. Related-record dependencies or scheduled changes may need different processing. Plan a backfill for existing records and a reconciliation check that detects stale values.

Test null inputs, boundary dates, each business branch and changes to referenced records. If users rely on the value immediately after a save, make that timing part of acceptance criteria.

The best fix preserves the calculation’s meaning and makes its maintenance clearer. A stored field that occasionally disagrees with the original formula is a data-quality defect, even if it saves successfully.

Keep reading

All articles