Salesforce Formulas Cheatsheet
Salesforce Formulas Cheatsheet
Abstract A formula is an algorithm that derives its value from other fields, expressions, or values. Use formulas in custom fields, evaluation criteria for data validation and workflow, and data calculations in reports, as well as the expression language in Visualforce. This tip sheet lists the operators and functions that formulas can include. See the online help for more information and examples.
Logical Operators
Operator = and == <> and != < > <= >= && || Description Evaluates if two values are equivalent. Evaluates if two values are not equivalent. Evaluates if a value is less than the value that follows this symbol. Evaluates if a value is greater than the value that follows this symbol. Evaluates if a value is less than or equal to the value that follows this symbol. Evaluates if a value is greater than or equal to the value that follows this symbol. Evaluates if two values or expressions are both true. Use this operator as an alternative to the logical function AND. Evaluates if at least one of multiple values or expressions is true. Use this operator as an alternative to the logical function OR.
Text Operators
Operator & Description Connects two or more strings.
Informational Functions
Function BLANKVALUE Description Determines if an expression has a value and returns a substitute expression if it does not. If the expression has a value, returns the value of the expression. Determines if an expression has a value and returns TRUE if it does not. If it contains a value, this function returns FALSE. Determines if an expression is null (blank) and returns TRUE if it is. If it contains a value, this function returns FALSE. Determines if an expression is null (blank) and returns a substitute expression if it is. If the expression is not blank, returns the value of the expression. Returns the previous value of a field.
ISBLANK
ISNULL
NULLVALUE
PRIORVALUE
Logical Functions
Function AND CASE Description Returns a TRUE response if all values are true; returns a FALSE response if one or more values are false. Checks a given expression against a series of values. If the expression is equal to a value, returns the corresponding result. If it is not equal to any values, it returns the else_result. Determines if expressions are true or false. Returns a given value if true and another value if false. Compares the value of a field to the previous value and returns TRUE if the values are different. If the values are the same, this function returns FALSE. Checks if the formula is running during the creation of a new record and returns TRUE if it is. If an existing record is being updated, this function returns FALSE. Determines if a text value is a number and returns TRUE if it is. Otherwise, it returns FALSE. Returns FALSE for TRUE and TRUE for FALSE. Determines if expressions are true or false. Returns TRUE if any expression is true. Returns FALSE if all expressions are false.
IF ISCHANGED
ISNEW
ISNUMBER NOT OR
Math Functions
Function ABS Description Calculates the absolute value of a number. The absolute value of a number is the number without its positive or negative sign. Rounds a number up to the nearest integer. Returns a value for e raised to the power of a number you specify. Returns a number rounded down to the nearest integer. Returns the natural logarithm of a specified number. Natural logarithms are based on the constant e value of 2.71828182845904. Returns the base 10 logarithm of a number. Returns the highest number from a list of numbers. Returns the lowest number from a list of numbers. Returns a remainder after a number is divided by a specified divisor.
Description Returns the nearest number to a number you specify, constraining the new number by a specified number of digits. Returns the positive square root of a given number.
Text Functions
Function BEGINS BR CONTAINS Description Determines if text begins with specific characters and returns TRUE if it does. Returns FALSE if it does not. Inserts a line break in a string of text. Compares two arguments of text and returns TRUE if the first argument contains the second argument. If not, returns FALSE. Returns the position of a string within a string of text represented as a number. Returns the users session ID. Creates a link to a URL specified that is linkable from the text specified. Inserts an image with alternate text and height/width specifications. Determines if any value selected in a multi-select picklist field equals a text literal you specify. Determines if the value of a picklist field is equal to a text literal you specify. Returns the specified number of characters from the beginning of a text string. Returns the number of characters in a specified text string. Converts all letters in the specified text string to lowercase. Any characters that are not letters are unaffected by this function. Locale rules are applied if a locale is provided. Inserts characters you specify to the left-side of a text string. Returns the specified number of characters from the middle of a text string given the starting position. Returns the specified number of characters from the end of a text string. Inserts characters that you specify to the right-side of a text string. Substitutes new text for old text in a text string.
Function TEXT
Description Converts a percent, number, date, date/time, or currency type field into text anywhere formulas are used. Also, converts picklist values to text in validation rules, formula fields, and field updates. Removes the spaces and tabs from the beginning and end of a text string. Converts all letters in the specified text string to uppercase. Any characters that are not letters are unaffected by this function. Locale rules are applied if a locale is provided. Converts a text string to a number.
TRIM UPPER
VALUE
Summary Functions
The following functions can only be used in custom summary formulas for summary and matrix reports. Function PARENTGROUPVAL Description This function returns the value of a specified parent grouping. A parent grouping is any level above the one containing the formula. You can only use this function in custom summary formulas for reports. This function returns the value of a specified previous grouping. A previous grouping is one that comes before the current grouping in the report. Choose the grouping level and increment. The increment is the number of columns or rows before the current summary. The default is 1; the maximum is 12. You can only use this function in custom summary formulas for reports.
PREVGROUPVAL
Advanced Functions
Function GETRECORDIDS INCLUDE LINKTO REGEX Description Returns an array of strings in the form of record IDs for the selected records in a list, such as a list view or related list. Returns content from an s-control snippet. Use this function to reuse common code in many s-controls. Returns a relative URL in the form of a link (href and anchor tags) for a custom s-control or Salesforce page. Compares a text field to a regular expression and returns TRUE if there is a match. Otherwise, it returns FALSE. A regular expression is a string used to describe a format of a string according to certain syntax rules.
Function REQUIRESCRIPT
Description Returns a script tag with source for a URL you specify. Use this function when referencing the Force.com AJAX Toolkit or other JavaScript toolkits. Returns a relative URL for an action, s-control, Visualforce page, or a file in a static resource archive in a Visualforce page. External websites can use absolute URLs for use in certain Visualforce components, such as <flow:interview>. Returns a value by looking up a related value on a custom object similar to the VLOOKUP() Excel function.
URLFOR
VLOOKUP
Encoding Functions
Function HTMLENCODE Description Encodes text and merge field values for use in HTML by replacing characters that are reserved in HTML, such as the greater-than sign (>), with HTML entity equivalents, such as >. Encodes text and merge field values for use in JavaScript by inserting escape characters, such as a backslash (\), before unsafe JavaScript characters, such as the apostrophe ('). Encodes text and merge field values for use in JavaScript within HTML tags by inserting escape characters before unsafe JavaScript characters and replacing characters that are reserved in HTML with HTML entity equivalents. Encodes text and merge field values for use in URLs by replacing characters that are illegal in URLs, such as blank spaces, with the code that represent those characters as defined in RFC 3986, Uniform Resource Identifier (URI): Generic Syntax. For example, blank spaces are replaced with %20, and exclamation points are replaced with %21.
JSENCODE
JSINHTMLENCODE
URLENCODE