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
Fight with the formula length limitFormula 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 sizeSalesforce 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.
Comments powered by CComment