Merge Fields and Formulas
Merge fields are dynamic placeholders in templates that pull data from Salesforce object fields or execute simple expressions to display contextual content. They follow the format:
{!ObjectName.FieldName}
or use expressions and functions within the braces for more advanced data manipulation.
Basic Merge Fields
These insert the value of a specific field from a Salesforce object into the template. Example:
{!Account.Name}, {!Account.BillingStreet}, {!Account.BillingCity}
Usage:
- Pulls the Account's Name, Billing Street, and Billing City field values.
- Displays literal text replaced dynamically by the corresponding Salesforce data.
Conditional Logic and Functions in Merge Fields
Salesforce merge fields support a full range of evaluable functions and conditional logic expressions, enabling dynamic content rendering based on data values, logical operations, and formula calculations. There is no fixed list of supported expressions any valid Salesforce formula can be used, and Salesforce fields may be freely inserted into formulas.
General Syntax for Conditional Logic and Functions
{!FORMULA_EXPRESSION}
You can insert any Salesforce formula expression inside the {! ... } delimiters.
Formula Support and Flexibility
- There is no limitation to specific functions or operators; you can use any valid Salesforce formula syntax.
- You can insert any field into the formula by referencing its API name.
- The examples below illustrate common usage but do not restrict what you can use.
Example Expressions (for illustration)
- Conditional logic with nested IFs:
{!IF(AnnualRevenue <= 1, "Small", IF(AnnualRevenue <= 2, "Medium", "Large"))}
This outputs "Small" for revenue ≤1, "Medium" for ≤2, otherwise "Large".
- Logical operators AND, OR, NOT:
{!AND(IsActive, AnnualRevenue > 5)} // true if both conditions are true.
Comparison Operators: =, !=, <, >, <=, >= work to compare fields and values.
- Common functions such as:
ISPICKVAL(field, "value") // Picklist value check.
ISBLANK(field) // Check if field is empty.
TEXT(field) // Convert field to text.
- Mathematical functions like
SUM(), ROUND(), ABS()can be used. - Date functions such as
TODAY(), NOW(), DATE(year, month, day), YEAR(date), etc.
Additional Examples
- Simple conditional text expression:
{!IF(Score > 90, "Excellent", "Needs Improvement")}
- Boolean expressions:
{!Account.Name != null} // Checks if Account Name exists.
- Nested IF with logical AND:
{!IF(AND(StageName = "Closed Won", Amount > 10000), "High Value", "Standard")}
Usage Notes
- You may combine any functions and operators for sophisticated dynamic content tailored to your logic needs.
- Always ensure data type compatibility when combining functions in your formulas.
- Nested expressions can add granularity and precision to your logic flows.
- Enclose string literals in double quotes.
- For very complex logic, consider creating Salesforce formula fields and referencing them within your merge field expressions.
Formula Functions
Salesforce formula functions enable you to format or manipulate field data dynamically using custom logic within your merge fields. Example syntax:
{!AFTER_N_FULL_MONTHS(TODAY(), 6)}
For an expanded list of Salesforce formula functions and detailed usage, please see the Formula Functions documentation.