Conditional statements show or hide parts of a Word template based on the underlying Salesforce data. Instead of maintaining several near-identical templates, you build one template that shows only the text, clauses or tables that apply to each record.
Use conditional statements to:
- Show a discount clause only when a Discount field is greater than zero.
- Include specific payment terms for certain customer types.
- Personalize greetings, disclaimers or offers based on account or contact details.
- Filter the rows of a related-object table so only matching records appear.
Basic syntax
Every conditional block has the same three-part structure:
{{IF|Field|Operator|Value}}
Content shown when the condition is TRUE
{{ELSE}}
Content shown when the condition is FALSE
{{ENDIF}}
Supported operators
Use these operators for the comparison inside an {{IF}} block:
| Operator | Meaning | What it does |
|---|---|---|
EQ | Equal to | Checks whether two values are exactly equal. |
NEQ | Not equal to | Checks whether two values are different. |
GT | Greater than | Checks whether a value is greater than the record value. |
GTE | Greater than or equal to | Checks whether a value is greater than or equal to the record value. |
LT | Less than | Checks whether a value is less than the record value. |
LTE | Less than or equal to | Checks whether a value is less than or equal to the record value. |
CONTAINS | Contains | Checks whether a text value contains a specified substring. |
STARTSWITH | Starts with | Checks whether a text value begins with a specified string. |
ENDSWITH | Ends with | Checks whether a text value ends with a specified string. |
ISNULL | Is null | Checks whether a field has no value (is null or empty). |
ISNOTNULL | Is not null | Checks whether a field contains a value (is not empty). |
Examples
Simple comparison (EQ)
Show account details only when the account type is exactly "Customer - Direct". Otherwise, show a fallback message.
{{IF|Account.Type|EQ|Customer - Direct}}
Account Name: {{Account.Name}}
Account Number: {{Account.AccountNumber}}
{{ELSE}}
This account is not a Direct Customer.
{{ENDIF}}
Result: If Account Type is "Customer - Direct", the document shows the account name and number. Otherwise, it shows "This account is not a Direct Customer."
Combine conditions (AND / OR)
Combine conditions with AND or OR to build more precise rules.
{{IF|Account.Type|EQ|Customer - Direct|AND|Account.ContactEmail__c|CONTAINS|@gmail.com}}
Customer Name: {{Account.Name}}
Email: {{Account.ContactEmail__c}}
Eligible for Gmail Customer Offer.
{{ELSE}}
Condition Not Matched.
{{ENDIF}}
Result: Both conditions must be true for the offer text to appear. If either one fails, the document shows "Condition Not Matched."
Conditions inside a related-object table
Conditional logic also works inside table rows generated from a related list, so you can change individual rows instead of the whole table. In this example, each contact's row shows the first name, unless the first name is "Jane". In that case, the row shows "InvalidName".
Create a two-column table with the headers First Name and Last Name. In the repeating row, enter this in the first cell:
{{TableStart:Account.r.Contacts}}{{IF|FirstName|EQ|Jane}}InvalidName{{ELSE}}{{FirstName}}{{ENDIF}}
And this in the second cell:
{{LastName}}{{TableEnd:Account.r.Contacts}}
Result: Every row in the Contact related list shows its own first and last name, except rows where the first name is "Jane", which show "InvalidName".
Related: Handle special characters in IF conditions · Use Word IF fields