Salesforce Formula Cheat Sheet

Here’s a basic guide with examples for some commonly used formula elements in Salesforce:

Basic Syntax

  • Field References:
    • Reference a field value: ObjectName__c.Field__c
  • Mathematical Operators:
    • Addition: +
    • Subtraction: -
    • Multiplication: *
    • Division: /
  • Comparison Operators:
    • Equal to: ==
    • Not equal to: !=
    • Greater than: >
    • Less than: <
    • Greater than or equal to: >=
    • Less than or equal to: <=

Text Functions

  • Concatenate:
    • Combine text fields: FirstName & " " & LastName
  • Text Length:
    • Get the length of a text field: LEN(TextField__c)
  • Substring:
    • Extract a portion of a text: MID(TextField__c, 2, 5) (starting at position 2 and taking 5 characters)

Date and Time Functions

  • Today’s Date:
    • TODAY()
  • Now:
    • NOW()
  • Date Difference:
    • Calculate the difference between two dates: CloseDate - CreatedDate

Logical Functions

  • IF Statement:
    • IF(Condition, ValueIfTrue, ValueIfFalse)
  • CASE Function:
    • CASE(FieldValue, "Value1", Result1, "Value2", Result2, DefaultResult)

Advanced Functions

  • ISBLANK:
    • Check if a field is blank: ISBLANK(Field__c)
  • ISNUMBER:
    • Check if a field is a number: ISNUMBER(Field__c)
  • HYPERLINK:
    • Create a hyperlink: HYPERLINK("http://www.example.com", "Link Text")
  • TEXT:
    • Convert a number to text: TEXT(NumberField__c)

Aggregate Functions

  • SUM:
    • Calculate the sum of a numeric field in a related list: SUM(relatedListName, Field__c)
  • AVG:
    • Calculate the average of a numeric field in a related list: AVG(relatedListName, Field__c)

Examples

  • Formula Field Example:
    • Concatenate first and last name: FirstName & " " & LastName
  • Validation Rule Example:
    • Allow saving only if the amount is greater than $100: Amount > 100
  • Workflow Rule Example:
    • Set a field value based on a condition: IF(StageName = "Closed", "Completed", "In Progress")

Remember, Salesforce formulas can be complex and vary depending on the use case (Validation Rules, Workflow Rules, Formula Fields, etc.). Always refer to the Salesforce documentation for the most up-to-date and detailed information on formula functions and syntax.