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:

OperatorMeaningWhat it does
EQEqual toChecks whether two values are exactly equal.
NEQNot equal toChecks whether two values are different.
GTGreater thanChecks whether a value is greater than the record value.
GTEGreater than or equal toChecks whether a value is greater than or equal to the record value.
LTLess thanChecks whether a value is less than the record value.
LTELess than or equal toChecks whether a value is less than or equal to the record value.
CONTAINSContainsChecks whether a text value contains a specified substring.
STARTSWITHStarts withChecks whether a text value begins with a specified string.
ENDSWITHEnds withChecks whether a text value ends with a specified string.
ISNULLIs nullChecks whether a field has no value (is null or empty).
ISNOTNULLIs not nullChecks 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."

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