# Become a Formula Ninja - Part 2. What Hidden Underwater?

Our real enemy is limits. Salesforce formulas looks easy only at first glance, it's hidding a whole ordeal.

## Let's equip with the knowledge about the main formula limits

- Maximum number of characters:
**3,900 characters** - Maximum formula size when saved:
**4,000 bytes** - Maximum formula size (in bytes) when compiled:
**5,000 bytes** - Maximum number of displayed characters after an evaluation of a formula expression:
**1,300 characters**

## Fight with the formula length limit

Formula stored in the database field, so, it's limited by**3,900 characters**. Character count includes spaces, carriage returns, and comments. If your formula includes multi-byte characters - the number of bytes is different than the number of characters. In that case, you cannot exceed the

**4,000 bytes**.

Might be a way out to move part of the formula into one or more secondary formula fields, and reference those in the main formula. Do not remove blank spaces, carriage returns, comments - this makes complex formulas harder to read.

## Fight with the formula compile size

Salesforce compile your formula, so, the database can execute it. It's limited by the size that can be executed by the database:**5,000 bytes**. There is no direct correlation between the compile size and the character limit. Reducing the number of characters in your formula doesn't help: comments, white space and field name length make no difference on the compile size. Breaking the formula into multiple fields doesn't help either because the compile size of each field is included in the main formula's compile size.

To decrease the compile size you can minimize the number of references to other fields. Now remember, the compile size of each field is included in the main formula's compile size. If it is not possible to minimize the number of fields then try to rethink your formula. Also, you can minimize the number of times formula functions are called. If your logic is too complex then think about process builders, workflow rules or triggers.

**Useful links:**

Comments powered by CComment