A Docs Made Easy template is an ordinary Word file with merge fields in double curly braces. When you generate a document, each merge field is replaced with Salesforce data, so learning five patterns (fields, related fields, tables, switches and conditions) covers most templates you'll build.
The parts of a template
Merge fields
A merge field is the object and field API name (not the label) inside {{ }}:
{{Account.Name}}
{{Opportunity.Invoice_Number__c}}
Since version 1.10, {{Account.Id}} replaces the old {!Account.Id}. Both still work, so older templates keep working, but use the new syntax for new templates. See Merge syntax: {{…}} vs {!…} explained.
Related (lookup) fields
To reach a field on a parent record, add the relationship between the object and the field:
| You want | Syntax |
|---|---|
| The account name on an opportunity | {{Opportunity.Account.Name}} |
| The name of the contact who signed a contract | {{Contract.CustomerSigned.Name}} |
| A field through a custom lookup | {{Receipt__c.Account__r.BillingCity}} |
You can pick these in the Merge Field Helper, or add the lookup on the Gather Data page. See Add fields from related records.
Tables for child records
To list child records (line items, contacts, cases), build a Word table and mark the row that repeats. Put TableStart in the first cell and TableEnd in the last cell, with the column fields in between:
| Product | Quantity | Price |
|---|---|---|
{{TableStart:Opportunity.r.OpportunityLineItems}}{{Name}} | {{Quantity}} | {{TotalPrice}}{{TableEnd:Opportunity.r.OpportunityLineItems}} |
The name after the colon identifies the data set. There are three forms, all valid, and the Merge Field Helper supports them:
- a related list (child relationship), such as
Account.r.Contacts, which fetches all related records (TableStart and TableEnd) - the alias you gave a child object on Gather Data, such as
ContactsAcc, which lets you sort, filter and limit the rows (Document Automation Wizard) - the alias of a SOQL query, such as
QueryData1. A query must have an alias, because the merge syntax uses it (old vs new syntax)
The related-list and alias forms fetch the same child records, so you can use either. When a SOQL query exists, the Merge Field Helper also shows its alias syntax. Copy the table syntax from the Merge Field Helper and use exactly the same name in TableStart and TableEnd.
Table tags such as RowNumber, Sum(Above), TableHide and TableGroup work with these rows.
Switches
A switch goes after the field name, inside the same braces, and changes how the value is displayed:
| Switch | Formats | Example | Output |
|---|---|---|---|
\@ | Dates and times | {{Account.CreatedDate \@ "MMMM d, yyyy"}} | June 3, 2025 |
\# | Numbers and currency | {{Account.AnnualRevenue \# $#,##0.00}} | $125,000.00 |
\* | Text case | {{Contact.Name \* upper}} | JOHN DOE |
\ PHONE: | Phone numbers | {{Account.Phone \ PHONE:(###) ###-####}} | (123) 456-7890 |
Each switch has a reference page: Date format, Time and AM/PM, Currency format, Upper case, Lower case and Phone format. For a region's number or currency style, combine \# with CurrencyCulture or NumberCulture.
Date patterns work with or without quotes: \@ "dd-MM-yyyy" and \@ dd-MM-yyyy give the same result. The phone switch works as both PHONE: and Phone:.
Every switch, parameter and condition works in both Basic and Pro. There's no Pro-only syntax.
Conditions
To show or hide content based on a value, use the native IF block:
{{IF|Account.Type|EQ|Customer - Direct}}
Account Number: {{Account.AccountNumber}}
{{ELSE}}
This account is not a direct customer.
{{ENDIF}}
Operators include EQ, NEQ, GT, LT, CONTAINS and ISNULL. See native conditional statements for the full list, and special characters in IF conditions for values that contain quotes or slashes.
You can also use a Microsoft Word IF field, for example { IF "{{Account.UpsellOpportunity__c}}"="Yes" "…" "…" }. Prefer the native syntax: it works inside tables and supports escape sequences. See Word IF fields.
The native IF accepts EQ and NEQ, not = and <>. The = and <> operators work only in TableHide:Master.
Where to copy the syntax
You rarely need to type syntax by hand:
- Merge Field Helper: opens when you add or upload a template. Click a field, then Copy to Clipboard. The Relationship Merge Fields tab lists related objects and the SOQL Query Fields tab lists queries.
- Available Merge Field: the button in each Add/Edit window on Gather Data.
See Copy merge fields with the Merge Field Helper.
When to use which
| If you need… | Use |
|---|---|
| A value from the record | A merge field: {{Opportunity.Name}} |
| A value from a parent record | A related field: {{Opportunity.Account.Name}} |
| One row per child record | TableStart / TableEnd in a table row |
| A date, number, currency, case or phone format | A switch: \@, \#, \*, \ PHONE: |
| Text that appears only sometimes | {{IF}} … {{ELSE}} … {{ENDIF}} |
| Data that relationships can't reach | A query or another data source. See Choose a data source |
Example: an opportunity summary
Template (Word):
{{Opportunity.Name}} for {{Opportunity.Account.Name}}
Close date: {{Opportunity.CloseDate \@ "MMMM d, yyyy"}}
Total: {{Opportunity.Amount \# $#,##0.00}}
{{IF|Opportunity.StageName|EQ|Closed Won}}Thank you for your order.{{ELSE}}This is a proposal, not an order.{{ENDIF}}
| Product | Quantity | Price |
|---|---|---|
{{TableStart:Opportunity.r.OpportunityLineItems}}{{Name}} | {{Quantity}} | {{TotalPrice}}{{TableEnd:Opportunity.r.OpportunityLineItems}} |
{{Sum(Above)}} |
Output for a Closed Won opportunity with two line items:
Burlington Textiles Weaving Plant Generator for Burlington Textiles Corp of America Close date: June 3, 2025 Total: $12,000.00 Thank you for your order.
| Product | Quantity | Price |
|---|---|---|
| Burlington Textiles Weaving Plant Generator GenWatt Diesel 1000kW | 1 | 10000 |
| Burlington Textiles Weaving Plant Generator SLA: Bronze | 2 | 2000 |
| 12000 |
Limits and gotchas
- Use API names. A label, a missing
__cor a typo gives an error such as DME-SF-002. So does a field your user can't read (field-level security). - Close every block. Every
{{IF}}needs an{{ENDIF}}, and everyTableStartneeds aTableEndwith the same name in the same row. A malformed tag gives DME-TPL-000. - Excel uses different syntax. Query fields in an Excel template are written
&=${{QueryAlias.Field}}. See SOQL query merge fields in Excel. - Tables show raw values.
{{TotalPrice}}and{{Sum(Above)}}print10000, not$10,000.00. Add a\#switch, or use AUTOSUM(ABOVE) for a formatted total. - If fields come out blank or as raw
{{…}}text, see Merge fields are blank or show tags.