Generate Documents with Salesforce Merge Fields with Dochly
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.
Double curly braces — always required. Opening and closing. No spaces between the braces and the content.
The Salesforce object API name — e.g. Opportunity, Account, Contact. Must match the primary object or a related object.
The Salesforce field API name — case-sensitive. Find it in Setup → Object Manager → Fields & Relationships.
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: {{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, TextArea, Email, Phone, URL
Renders as plain text. No filter needed. Long text area fields wrap naturally within the document layout.
Number, Integer, Percent
Renders as a number. Use | number to apply thousand separators. Use | currency for money values.
Currency fields
Use | currency filter — outputs symbol, decimal places, and thousand separators matching your org's currency settings.
Date fields
Use | date: "format" filter. Without it, raw date strings (2026-06-15) appear. Always apply date formatting on customer-facing documents.
DateTime fields
Use | date: "format" to output date only, or include time tokens to show both date and time.
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.
Boolean / Checkbox fields
Renders as true or false by default. Use conditional logic with {IF} to output custom labels (e.g. "Yes" / "No").
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 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
| Merge field | Label | Notes |
|---|---|---|
| {{Opportunity.Name}} | Opportunity Name | Deal/opportunity title |
| {{Opportunity.Amount | currency}} | Amount | Deal value — always apply | currency |
| {{Opportunity.CloseDate | date: "MMMM d, yyyy"}} | Close Date | Format date for readability |
| {{Opportunity.StageName}} | Stage | Current pipeline stage |
| {{Opportunity.Description}} | Description | Long text — may wrap across lines |
| {{Opportunity.OwnerId}} | Owner ID | Use {{Opportunity.Owner.Name}} for name |
| Merge field | Label | Notes |
|---|---|---|
| {{Account.Name}} | Account Name | Company name |
| {{Account.BillingStreet}} | Billing Street | First line of billing address |
| {{Account.BillingCity}} | Billing City | Billing address city |
| {{Account.BillingState}} | Billing State | Billing address state/province |
| {{Account.BillingPostalCode}} | Billing Zip | Billing address postal code |
| {{Account.Phone}} | Phone | Main account phone number |
| Merge field | Label | Notes |
|---|---|---|
| {{Contact.FirstName}} | First Name | Contact first name |
| {{Contact.LastName}} | Last Name | Contact last name |
| {{Contact.Title}} | Title | Job title — may be blank |
| {{Contact.Email}} | Primary email address | |
| {{Contact.Phone}} | Direct Phone | Direct phone number |
| {{Contact.Department}} | Department | Department 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.
| Filter | Output example | Use for |
|---|---|---|
| | date: "MMMM d, yyyy" | June 15, 2026 | Formal documents — contracts, proposals |
| | date: "MMM d, yyyy" | Jun 15, 2026 | Shorter formal format |
| | date: "dd/MM/yyyy" | 15/06/2026 | UK / European date format |
| | date: "MM/dd/yyyy" | 06/15/2026 | US date format |
| | date: "d MMMM yyyy" | 15 June 2026 | Legal documents |
| | date: "yyyy-MM-dd" | 2026-06-15 | ISO format — system-to-system docs |
| | date: "MMMM yyyy" | June 2026 | Month and year only |
| | date: "EEEE, MMMM d" | Monday, June 15 | Meeting or event documents |
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
| Filter | Output example | Use for |
|---|---|---|
| | currency | $12,500.00 | Money values — uses org currency symbol and decimal settings |
| | currency: "GBP" | £12,500.00 | Specific currency override |
| | number | 12,500 | Numbers with thousand separators, no currency symbol |
| | number: 2 | 12,500.00 | Number with specified decimal places |
| | number: 0 | 12,500 | Whole numbers only, no decimals |
| | percent | 15% | Percentage fields — appends % symbol |
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
| Filter | Output example | Use for |
|---|---|---|
| | upcase | ACME CORPORATION | ALL CAPS — headings, document titles |
| | downcase | acme corporation | Lowercase — reference codes, IDs |
| | capitalize | Acme Corporation | Title case each word |
| | truncate: 50 | This is a very long description that has been… | Limit long text to N characters |
| | strip | Acme Corporation | Remove leading/trailing whitespace |
| | replace: "old", "new" | Customized text | String replacement within a field value |
{{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.
{{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.
Title: {{Contact.Title}}
{END IF}
← The "Title:" label and value only appear when the Title field has a value
This agreement has been finalised.
{ELSE}
This proposal is subject to change pending final approval.
{END IF}
[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 field | Output | Notes |
|---|---|---|
| {{TODAY | date: "MMMM d, yyyy"}} | June 15, 2026 | Today's date at generation time — always apply date filter |
| {{NOW | date: "MMMM d, yyyy HH:mm"}} | June 15, 2026 14:30 | Current date and time at generation |
| {{CurrentUser.Name}} | Sarah Johnson | Full name of the user who triggered generation |
| {{CurrentUser.Email}} | sarah@company.com | Email of the generating user |
| {{CurrentUser.Title}} | Account Executive | Title of the generating user |
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
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.
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.
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.
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
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.
Rated 5 stars · Native Salesforce app · Free to install