Add Salesforce Merge Fields to a Document Template
What are merge fields?
A merge field is a placeholder in your document template that references a specific Salesforce field. When Dochly generates a document from a record, it scans the template for merge fields and replaces each one with the actual value from that record.
For example, if your template contains {{Account.Name}} and the document is generated from an Opportunity linked to "Acme Corp", the generated document will display Acme Corp in that position — automatically, without any manual input.
Pull live data from Salesforce records directly into your document at generation time — no copy-paste, no manual data entry, no formatting errors.
Static text. Merge fields are always connected to a Salesforce field — if the field value changes on the record, the next generated document reflects the updated value.
How to insert a merge field
There are two ways to insert a merge field in the Dochly template editor:
Use the merge field picker (recommended)
Place your cursor in the template where you want the data to appear. Click the Merge Fields button in the editor toolbar. Browse or search for the field you want — fields are organized by object. Click the field to insert it. The merge field placeholder appears at your cursor position.
The picker shows all fields available on the primary object and its related objects. This is the safest method — it ensures the field syntax is always correct.
Type the merge field directly
If you know the exact field API name, you can type the merge field directly using double curly brace syntax:
Use this method only when you're confident about the field API name. A single typo will cause the merge field to fail silently — outputting a blank instead of the expected value.
Always use the field API name — not the field label. The API name is the technical name used in Salesforce (e.g. BillingCity, not "Billing City"). The merge field picker handles this automatically.
Standard object fields
These are the most commonly used merge fields across Dochly templates. They pull from the primary object and its directly related standard objects.
| Merge Field | Field Label | Notes |
|---|---|---|
| {{Opportunity.Name}} | Opportunity Name | The name of the deal |
| {{Opportunity.Amount}} | Amount | Deal value — format with currency options |
| {{Opportunity.CloseDate}} | Close Date | Returns date — apply formatting as needed |
| {{Opportunity.StageName}} | Stage | Current pipeline stage |
| {{Opportunity.Type}} | Opportunity Type | New Business, Renewal, etc. |
| {{Opportunity.Description}} | Description | Freetext field — may be blank |
| Merge Field | Field Label | Notes |
|---|---|---|
| {{Account.Name}} | Account Name | Company name |
| {{Account.BillingStreet}} | Billing Street | First line of billing address |
| {{Account.BillingCity}} | Billing City | Billing city |
| {{Account.BillingState}} | Billing State/Province | State or province |
| {{Account.BillingPostalCode}} | Billing Zip/Postal Code | Postal code |
| {{Account.BillingCountry}} | Billing Country | Useful for conditional legal sections |
| {{Account.Phone}} | Account Phone | Main account phone number |
| {{Account.Website}} | Website | Account website URL |
| Merge Field | Field Label | Notes |
|---|---|---|
| {{Contact.FirstName}} | First Name | Contact first name |
| {{Contact.LastName}} | Last Name | Contact last name |
| {{Contact.Email}} | Primary contact email | |
| {{Contact.Title}} | Title | Job title — may be blank |
| {{Contact.Phone}} | Phone | Contact direct phone |
Special fields
Dochly provides several special merge fields that are not tied to a specific Salesforce record field — they generate values automatically at document creation time.
| Merge Field | What It Outputs | Notes |
|---|---|---|
| {{TODAY}} | Today's date | Auto-populated at generation time. Apply date format as needed. |
| {{NOW}} | Current date and time | Includes time stamp — useful for compliance documents. |
| {{PAGE}} | Current page number | Used in footer sections for multi-page documents. |
| {{TOTAL_PAGES}} | Total page count | Use with {{PAGE}} for "Page 1 of 3" format. |
| {{GENERATED_BY}} | Name of user who generated the document | Useful for internal audit and accountability. |
Custom fields
All custom fields in your Salesforce org are available as merge fields in Dochly. Custom fields use the same syntax as standard fields — {{ObjectName.FieldAPIName}} — but their API names always end in __c.
{{Opportunity.Contract_Type__c}} — custom contract type picklist
{{Opportunity.Payment_Terms__c}} — custom payment terms field
{{Account.Tax_ID__c}} — custom tax ID on Account
{{Contact.Signatory_Title__c}} — custom title field on Contact
{{Opportunity.Billing_Region__c}} — custom billing region field
To find the API name of a custom field: in Salesforce Setup, go to Object Manager → [Object Name] → Fields & Relationships. The API name column shows the exact name to use in your merge field syntax.
Date and number formatting
By default, date and number fields output in Salesforce's raw format. You can apply formatting options to control how they appear in the generated document.
{{Opportunity.CloseDate | date: "MM/dd/yyyy"}} → 06/15/2026
{{Opportunity.CloseDate | date: "dd MMM yyyy"}} → 15 Jun 2026
{{TODAY | date: "MMMM d, yyyy"}} → today formatted
{{Opportunity.Amount | number: "0,0"}} → 12,500
{{OpportunityLineItem.Quantity | number: "0"}} → 5
Merge fields in dynamic tables
Dynamic tables use repeating row merge fields to generate one table row per related record — products, line items, tasks, or any related list in Salesforce. The table expands automatically based on how many related records exist on the deal.
{{OpportunityLineItem.Name}} | {{OpportunityLineItem.Quantity}} | {{OpportunityLineItem.UnitPrice | currency}} | {{OpportunityLineItem.TotalPrice | currency}}
{END REPEAT}
Subtotal: {{Opportunity.Amount | currency}}
If an Opportunity has zero line items, the repeating section generates zero rows — the table header still appears but the body is empty. Use conditional logic to wrap the entire table and hide it when no products exist if needed.
Handling blank outputs
When a merge field references a Salesforce field that is empty on the record, Dochly outputs a blank space by default. There are two approaches to handle this gracefully:
{{Opportunity.Description | default: "N/A"}} — shows "N/A" if Description is blank
Title: {{Contact.Title}}
{END IF}
The conditional approach is better when the entire line or section should be hidden rather than showing a fallback value. Use the default value approach for fields that should always appear with some content.
Common merge field errors
The field is empty on the record, the API name is wrong, or the field is restricted by field-level security for the generating user's profile.
The field was typed incorrectly — check for mismatched curly braces, spaces inside the field name, or an incorrect object/field separator.
The field exists but the value is null on the record. Add a | default: "" fallback or wrap in a conditional block to suppress null output.
The relationship path is incorrect or the related record doesn't exist. Check the relationship API name in Salesforce Object Manager. See troubleshooting guide.
Frequently asked questions
You now have everything you need to add merge fields to your templates accurately. Next steps: Build a branded document template · Create a contract template · Troubleshooting merge field errors
Rated 5 stars · Native Salesforce app · Free to install