Conditional statements control what content appears in a generated document based on the values of Salesforce fields or parameters. One template can then produce documents tailored to each recipient, without separate template versions.

This article uses Microsoft Word IF fields. For most templates, use the native {{IF}} syntax instead. It works inside tables and supports escape sequences for special characters. See A guide to native conditional statements.

Insert an IF field

  1. Open your template in Microsoft Word.

  2. On the Insert tab, click Quick Parts, then select Field…. The Field dialog opens.

  3. In the Field names list, select IF, then click OK. Word inserts the placeholder text "Error! Missing test condition."

    Field dialog with IF selected in the Field names list

  4. Right-click the placeholder text and select Toggle Field Codes. The field code appears in braces.

  5. Enter your condition. In this example, the document shows one sentence when the UpsellOpportunity__c field is "Yes" and another sentence otherwise:

    { IF "{{Account.UpsellOpportunity__c}}"="Yes" "This account has an active upsell opportunity under review." "No upsell opportunities are currently identified for this account." \* MERGEFORMAT }
    

    Word template with an IF field code that checks the Upsell Opportunity field

  6. Right-click the field code and select Toggle Field Codes again to switch back to the normal view. Your template is ready to use.

Example output

When Upsell Opportunity is "No" on the account record, the generated document shows the "No upsell opportunities" sentence:

Generated document showing the sentence for accounts without an upsell opportunity

When Upsell Opportunity is "Yes" on the account record, the generated document shows the "active upsell opportunity" sentence:

Generated document showing the sentence for accounts with an active upsell opportunity

Related: A guide to native conditional statements · Handle special characters in IF conditions