Help Center Document Generation Generate with Merge Fields

Generate Documents with Salesforce Merge Fields with Dochly

Updated June 2026 10 min read Document Generation
Merge fields are the mechanism that transforms a static document template into a dynamic document populated with live Salesforce data. This is the complete Dochly merge field reference — covering field syntax, all supported field types, date and currency formatting, text transformations, default values, conditional display, related object traversal, and system fields. Use this guide as a reference whenever you build or update a template.

Merge field syntax

Every Dochly merge field follows the same pattern — double curly braces wrapping an object name, a dot separator, and a field API name. Filters are optional and follow a pipe character.

{{Object.FieldName | filter}}
{{ }}

Double curly braces — always required. Opening and closing. No spaces between the braces and the content.

Object

The Salesforce object API name — e.g. Opportunity, Account, Contact. Must match the primary object or a related object.

FieldName

The Salesforce field API name — case-sensitive. Find it in Setup → Object Manager → Fields & Relationships.

| filter

Optional output modifier — formats dates, currencies, text. Multiple filters can be chained with additional pipe characters.

Always use the merge field picker in the template editor. It inserts the correct syntax automatically. Typing merge fields manually is the most common source of errors — a single misplaced space or missing brace causes the field to appear as raw text in the document instead of the value.

Valid and invalid syntax examples
✓ Valid: {{Opportunity.Name}}
✓ Valid: {{Account.BillingCity}}
✓ Valid: {{Opportunity.CloseDate | date: "MMMM d, yyyy"}}
✓ Valid: {{Opportunity.Amount | currency}}

✗ Invalid: {Opportunity.Name} ← single curly brace
✗ Invalid: {{ Opportunity.Name }} ← spaces inside braces
✗ Invalid: {{opportunity.name}} ← wrong case (API names are case-sensitive)
✗ Invalid: {{Opportunity Name}} ← missing dot separator

Field types and how they render

Different Salesforce field types render differently in generated documents. Applying the correct filter ensures the output is formatted correctly.

Text

Text, TextArea, Email, Phone, URL

Renders as plain text. No filter needed. Long text area fields wrap naturally within the document layout.

Number

Number, Integer, Percent

Renders as a number. Use | number to apply thousand separators. Use | currency for money values.

Currency

Currency fields

Use | currency filter — outputs symbol, decimal places, and thousand separators matching your org's currency settings.

Date

Date fields

Use | date: "format" filter. Without it, raw date strings (2026-06-15) appear. Always apply date formatting on customer-facing documents.

DateTime

DateTime fields

Use | date: "format" to output date only, or include time tokens to show both date and time.

Picklist

Picklist and Multi-select

Renders the picklist label (display value) by default — not the API value. Multi-select picklist values are rendered as a comma-separated list.

Checkbox

Boolean / Checkbox fields

Renders as true or false by default. Use conditional logic with {IF} to output custom labels (e.g. "Yes" / "No").

Formula

Formula fields

Renders the formula's output value. Apply the appropriate filter based on the formula's return type — text, number, date, or currency.

Lookup

Lookup and Master-Detail

Renders the related record's name by default. To access other fields on the related record, traverse the relationship in the merge field path.


Standard object fields — quick reference

Opportunity — most commonly used fields
Merge fieldLabelNotes
{{Opportunity.Name}}Opportunity NameDeal/opportunity title
{{Opportunity.Amount | currency}}AmountDeal value — always apply | currency
{{Opportunity.CloseDate | date: "MMMM d, yyyy"}}Close DateFormat date for readability
{{Opportunity.StageName}}StageCurrent pipeline stage
{{Opportunity.Description}}DescriptionLong text — may wrap across lines
{{Opportunity.OwnerId}}Owner IDUse {{Opportunity.Owner.Name}} for name
Account — most commonly used fields
Merge fieldLabelNotes
{{Account.Name}}Account NameCompany name
{{Account.BillingStreet}}Billing StreetFirst line of billing address
{{Account.BillingCity}}Billing CityBilling address city
{{Account.BillingState}}Billing StateBilling address state/province
{{Account.BillingPostalCode}}Billing ZipBilling address postal code
{{Account.Phone}}PhoneMain account phone number
Contact — most commonly used fields
Merge fieldLabelNotes
{{Contact.FirstName}}First NameContact first name
{{Contact.LastName}}Last NameContact last name
{{Contact.Title}}TitleJob title — may be blank
{{Contact.Email}}EmailPrimary email address
{{Contact.Phone}}Direct PhoneDirect phone number
{{Contact.Department}}DepartmentDepartment or team


Date and time formatting

Date fields in Salesforce store raw ISO 8601 values (2026-06-15). Without a date filter, that's what appears in your document. Always apply a date format filter on customer-facing documents.

FilterOutput exampleUse for
| date: "MMMM d, yyyy"June 15, 2026Formal documents — contracts, proposals
| date: "MMM d, yyyy"Jun 15, 2026Shorter formal format
| date: "dd/MM/yyyy"15/06/2026UK / European date format
| date: "MM/dd/yyyy"06/15/2026US date format
| date: "d MMMM yyyy"15 June 2026Legal documents
| date: "yyyy-MM-dd"2026-06-15ISO format — system-to-system docs
| date: "MMMM yyyy"June 2026Month and year only
| date: "EEEE, MMMM d"Monday, June 15Meeting or event documents
Date format token reference
yyyy — 4-digit year (2026) yy — 2-digit year (26)
MMMM — Full month name (June) MMM — Abbreviated (Jun) MM — Zero-padded number (06)
d — Day number (15) dd — Zero-padded day (05)
EEEE — Full day name (Monday) EEE — Abbreviated (Mon)
HH — 24-hr hour (14) hh — 12-hr hour (02) mm — Minutes (30) a — AM/PM

Currency and number formatting

FilterOutput exampleUse for
| currency$12,500.00Money values — uses org currency symbol and decimal settings
| currency: "GBP"£12,500.00Specific currency override
| number12,500Numbers with thousand separators, no currency symbol
| number: 212,500.00Number with specified decimal places
| number: 012,500Whole numbers only, no decimals
| percent15%Percentage fields — appends % symbol
Currency formatting in context
Proposal Total: {{Opportunity.Amount | currency}} → $45,000.00
Unit Price: {{OpportunityLineItem.UnitPrice | currency}} → $1,200.00
Discount: {{OpportunityLineItem.Discount | number: 1}}% → 10.0%
Qty: {{OpportunityLineItem.Quantity | number: 0}} → 5

Text filters and transformations

FilterOutput exampleUse for
| upcaseACME CORPORATIONALL CAPS — headings, document titles
| downcaseacme corporationLowercase — reference codes, IDs
| capitalizeAcme CorporationTitle case each word
| truncate: 50This is a very long description that has been…Limit long text to N characters
| stripAcme CorporationRemove leading/trailing whitespace
| replace: "old", "new"Customized textString replacement within a field value
Chaining multiple filters
Chain filters left to right with pipe characters:
{{Account.Name | upcase | truncate: 30}} ← uppercase then truncate to 30 chars
{{Contact.FirstName | capitalize | strip}} ← capitalize then strip whitespace

Default values for empty fields

When a Salesforce field is empty, Dochly outputs blank by default. Use the | default: filter to specify what should appear instead — preventing blank gaps and "null" text in the generated document.

Output blank if empty (suppress null):
{{Contact.Title | default: ""}} → blank (no "null" text)

Output fallback text if empty:
{{Contact.Title | default: "Representative"}} → "Representative" if Title is blank
{{Opportunity.Description | default: "N/A"}} → "N/A" if Description is blank
{{Account.BillingState | default: "—"}} → em dash if State is blank

Combine default with other filters:
{{Opportunity.Amount | currency | default: "$0.00"}} → "$0.00" if Amount is null

Conditional field display

Use conditional logic to show or hide specific fields or sections based on field values. This is different from hiding an entire document section — conditional fields control whether individual pieces of text appear.

Show text only when a field has a value
{IF Contact.Title != null}
Title: {{Contact.Title}}
{END IF}

← The "Title:" label and value only appear when the Title field has a value
Show different text based on a checkbox
{IF Opportunity.IsClosed = true}
This agreement has been finalised.
{ELSE}
This proposal is subject to change pending final approval.
{END IF}
Show different content based on a picklist value
{IF Opportunity.Type = "New Business"}
[New customer terms and conditions]
{ELSE IF Opportunity.Type = "Renewal"}
[Renewal terms — existing customer]
{ELSE}
[Standard terms]
{END IF}

System fields — TODAY, NOW, and current User

Dochly provides system merge fields that insert dynamic values at generation time — not from any specific Salesforce record.

Merge fieldOutputNotes
{{TODAY | date: "MMMM d, yyyy"}}June 15, 2026Today's date at generation time — always apply date filter
{{NOW | date: "MMMM d, yyyy HH:mm"}}June 15, 2026 14:30Current date and time at generation
{{CurrentUser.Name}}Sarah JohnsonFull name of the user who triggered generation
{{CurrentUser.Email}}sarah@company.comEmail of the generating user
{{CurrentUser.Title}}Account ExecutiveTitle of the generating user
Common system field usage
Document header:
Date: {{TODAY | date: "MMMM d, yyyy"}}
Prepared by: {{CurrentUser.Name}}, {{CurrentUser.Title}}

Footer:
Generated on {{TODAY | date: "d MMM yyyy"}} by {{CurrentUser.Name}}

Best practices

Always use the field picker

The merge field picker in the template editor inserts correct syntax automatically. Never type merge fields manually — even experienced template builders make typos that cause silent failures.

Add defaults to all optional fields

Any field that isn't always populated should have a | default: "" or a meaningful fallback value. This prevents "null" appearing in documents generated from incomplete records.

Format all dates and currencies

Always apply date and currency filters on customer-facing documents. Raw values like "2026-06-15" and "45000" without formatting look unprofessional and can cause confusion for international recipients.

Preview from real records

Test merge fields by generating a preview from a real Salesforce record — not a test record with dummy data. Real records expose edge cases like blank fields, unusual characters, and long text that dummy data doesn't.


Frequently asked questions

Go to Salesforce Setup → Object Manager → [Object Name] → Fields & Relationships. Find the field in the list and click it — the API Name is shown in the field detail. Custom field API names always end in __c (e.g. Billing_Reference__c). Copy it exactly — API names are case-sensitive in Dochly merge field syntax.
Yes. Rich text area fields in Salesforce can be included as merge fields in Dochly templates. The HTML content is rendered — bold, italic, lists, and line breaks are preserved in the generated document. Use {{Object.RichTextField__c}} without any special filter. Note that complex HTML (embedded images, custom styles) may not render identically to how it appears in Salesforce.
Yes. Merge fields work in headers and footers just like the document body. Common uses: {{TODAY}} in the header for the document date, {{Opportunity.Name}} in the footer as a reference, and {{CurrentUser.Name}} in the footer as the preparer's name. System fields like {{TODAY}} and {{CurrentUser}} are particularly useful in headers and footers.
Dochly supports up to 5 levels of relationship traversal in a single merge field path. In practice, most templates use 1–2 levels (e.g. Contact.Account.Name). Deeper traversal paths work but increase generation time slightly as Dochly resolves each level from Salesforce. Use the merge field picker to build traversal paths — it shows available relationships at each level.

You now have the complete merge field reference for Dochly document generation. Next in this series: How to add a document generation button in Salesforce with Dochly — add the Generate button to any Salesforce object page layout.

Dochly
Salesforce AppExchange — UTECH HUB Install Dochly on AppExchange

Rated 5 stars · Native Salesforce app · Free to install