# What are the compiled costs of each Formula function

Each formula function has a compiled cost that contributes towards the hard 5000 compiled character formula limit.

What are the current compiled costs associated with each formula function?

Notes:

1. There are a lot of functions to check, so building a complete list will take a bit of work. I’ve made this a community post so others can contribute if they like.
2. Salesforce changes the implementation of functions over time, so the exact costs can change.
3. Determining the compiled formula cost currently relies of comparing the compiled size of a formula that includes the function with one that doesn’t. There may be other factors that affect the compiled size of a function. For instance, some functions cost depends on the argument values.

# Math Operators

• +: 3
• -: 3
• *: 3
• /: 3
• ^: 9
• (): 1 each (each pair costs 2)

# Logical Operators and Logical Functions

• AND/&&: 7 for two parameters, 6 for each extra parameter
• CASE: 27 for minimum 4 parameters, 12 for each extra pair of parameters
• In Spring ’21 using a picklist field, 84 minimum for 4 parameters, 64 for each extra pair of parameters
• IF: 26
• ISNULL: 10
• ISNUMBER: 81
• NOT, !: 6
• OR/||: 6 for two parameters, 5 for each extra parameter
• <, >, =: 3
• >=, <=, <>: 4
• ISCHANGED: ?
• ISNEW: ?

• &, +: 4

# Date and Time Functions

• +: 3
• DATE: ?
• DATEVALUE: 30
• DATETIMEVALUE: ?
• DAY: 19
• MONTH: 21
• NOW: 7
• TODAY: 9
• YEAR: 20

• BLANKVALUE
• ISBLANK
• ISNULL
• NULLVALUE
• PRIORVALUE

# Math Functions

• ABS: 5
• CEILING: 112
• EXP: 5
• FLOOR: 112
• LN: 4
• LOG: 9
• MAX: 12 for two parameters, plus 2 per extra parameter
• MIN: 9 for two parameters, plus 2 per extra parameter
• MOD: 7, plus length of second parameter
• ROUND: 9, plus length of second parameter
• SQRT: 6

# Text Functions

• BEGINS – 57 + length of length parameter
• BR – 18
• CASESAFEID ~ 2073. Depends on Reference & Object. `CASESAFEID(Foo__c)` takes less than `CASESAFEID(Foo__r.Id)`. Standard Objects seem to take less than custom – Idea to reduce size
• CONTAINS – 58 +length of length parameter
• FIND – 46
• GETSESSIONID – 13
• HYPERLINK – Base of 88, increases by 1 for each `url` and `friendly_name` character.
• IMAGE – Base of 19, increases by 1 for each `image_url` and `alternative_text` character
• INCLUDES
• ISPICKVAL – ~ 51-53, no cost/optimized out if the test value is not one of the active or inactive picklist values
• LEFT – 26+length of length parameter
• LEN – 15
• LOWER – 37
• MID – 38+length of length parameters.
• RIGHT – 45+length of length parameter
• SUBSTITUTE – 29
• TEXT – 42 for Number field, 64 for DateTime field
• TRIM – 18
• UPPER – 37
• VALUE – 23

# Summary Functions

• PARENTGROUPVAL
• PREVGROUPVAL

• GETRECORDIDS
• INCLUDE
• REGEX
• REQUIRESCRIPT
• URLFOR
• VLOOKUP

# Encoding Functions

• HTMLENCODE
• JSENCODE
• JSINHTMLENCODE
• URLENCODE

# Other Notes

Some optizations exist in the compiler engine. For example, mathematical operations that do not involve fields are “solved” to their final value. For example, `1+5` compiles to just 1 character, because the result is always 6. Similarly, functions like NULLVALUE use no extra characters if the field is required (e.g. `NULLVALUE(Name,'No Name')` uses 12 characters).