Additional Functions for Formulas

To build logic into formulas, use these functions with the text, number, and datetime data types.

case

Use a case statement to handle if/then logic. A case statement always has a pair of where and then statements.

Syntax

case [primary_expr]
    when condition
    then result_expression
    else 
        default_expression
end

Parameters

  • primary_expression—Optional. Any valid expression to compare against a set of expressions. The primary expression is compared to the expression in each when clause for equivalency. If these expressions are equivalent, the expression in the then clause will be returned.
  • condition—The condition of a case statement can take two forms:
    • An expression that is compared against a set of possible values.
    • A boolean expression that evaluates to true, false, or null.
  • result_expression—The expression returned when the primary_expression satisfies the condition and evaluates to True.
  • default_expression—If neither of the previous comparisons evaluate to True, this expression is returned.

Examples

case ShippingState__c
    when 'CA'
    then 'California'
    else 
        'Other'
end
case 
    when "ShippingState__c" = 'CA'
    then 'California'
    else 
        'Other'
end

coalesce

Use the coalesce function as shorthand for case statements. This function replaces null values with another value.

Syntax

coalesce(expression1, expression2)

Parameters

  • expression1—The first column or text string to search for a non-null value.
  • expression2—The next column or text string to search for a non-null value.

Example

coalesce(city, null) 

Returns

Returns the first non-null value. If there isn’t one, then the function returns null.

sequence

Use the sequence function to create a sequence of numbers or dates by defining the start and end values and the interval between each value.

Syntax

sequence(start,stop,step)

Parameters

  • start—A field or number.
  • stop—A field or number.
  • step—A field, number, or date interval.

Example

sequence(start_field, stop_field, interval 1 day)

Returns

Returns an array with one element for each value.

UUID

Use the uuid function to generate a unique identifier for rows in a table.

Syntax

uuid()

Parameters

  • None

Returns

Returns a 36-character, universally unique identifier string for each row in a table.