36

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?

2
  • Are you still editing, or did you want some help?
    – sfdcfox
    Commented Nov 13, 2016 at 21:34
  • @sfdcfox Taking a break from it for the moment. Will come back to it later as time permits. Commented Nov 13, 2016 at 21:49

1 Answer 1

30

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: ?

Text Operators

  • &, +: 4

Date and Time Functions

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

Informational Functions

  • 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
  • LPAD
  • MID - 38+length of length parameters.
  • RIGHT - 45+length of length parameter
  • RPAD
  • SUBSTITUTE - 29
  • TEXT - 42 for Number field, 64 for DateTime field
  • TRIM - 18
  • UPPER - 37
  • VALUE - 23

Summary Functions

  • PARENTGROUPVAL
  • PREVGROUPVAL

Advanced Functions

  • GETRECORDIDS
  • INCLUDE
  • LINKTO
  • 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).

4
  • @sfdcfox Thanks, I'll merge them into the answer. I made it a community wiki if you want to directly edit it. Commented Nov 13, 2016 at 21:48
  • 2
    I didn't want to accidentally overwrite if you were editing still.
    – sfdcfox
    Commented Nov 13, 2016 at 21:51
  • @sfdcfox Interesting note you made about the optimizations for primitives. Had to revise some of my Text function numbers as they expanded when using actual fields rather than primitives. Commented Nov 14, 2016 at 0:01
  • 3
    oddly enough, if you add a string literal of 5000 characters it only says it's 3900 compiled length
    – NSjonas
    Commented Nov 18, 2016 at 3:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .