Help Center Template Editor Add Merge Fields

Add Salesforce Merge Fields to a Document Template

Updated June 2026 8 min read Template Editor
Merge fields are what make Dochly templates dynamic. Instead of static text, merge fields are placeholders in your template that get replaced with live data from the Salesforce record at the moment a document is generated — account names, deal amounts, contact details, product line items, and any other field in your org. This guide covers everything you need to know: how to insert merge fields, which fields are available, how to access related object data, and how to handle edge cases like blank fields and formatting.

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.

What merge fields do

Pull live data from Salesforce records directly into your document at generation time — no copy-paste, no manual data entry, no formatting errors.

What merge fields are not

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:

1

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.

2

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:

{{ObjectName.FieldAPIName}}

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.

Opportunity fields
Merge FieldField LabelNotes
{{Opportunity.Name}}Opportunity NameThe name of the deal
{{Opportunity.Amount}}AmountDeal value — format with currency options
{{Opportunity.CloseDate}}Close DateReturns date — apply formatting as needed
{{Opportunity.StageName}}StageCurrent pipeline stage
{{Opportunity.Type}}Opportunity TypeNew Business, Renewal, etc.
{{Opportunity.Description}}DescriptionFreetext field — may be blank
Account fields
Merge FieldField LabelNotes
{{Account.Name}}Account NameCompany name
{{Account.BillingStreet}}Billing StreetFirst line of billing address
{{Account.BillingCity}}Billing CityBilling city
{{Account.BillingState}}Billing State/ProvinceState or province
{{Account.BillingPostalCode}}Billing Zip/Postal CodePostal code
{{Account.BillingCountry}}Billing CountryUseful for conditional legal sections
{{Account.Phone}}Account PhoneMain account phone number
{{Account.Website}}WebsiteAccount website URL
Contact fields
Merge FieldField LabelNotes
{{Contact.FirstName}}First NameContact first name
{{Contact.LastName}}Last NameContact last name
{{Contact.Email}}EmailPrimary contact email
{{Contact.Title}}TitleJob title — may be blank
{{Contact.Phone}}PhoneContact 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 FieldWhat It OutputsNotes
{{TODAY}}Today's dateAuto-populated at generation time. Apply date format as needed.
{{NOW}}Current date and timeIncludes time stamp — useful for compliance documents.
{{PAGE}}Current page numberUsed in footer sections for multi-page documents.
{{TOTAL_PAGES}}Total page countUse with {{PAGE}} for "Page 1 of 3" format.
{{GENERATED_BY}}Name of user who generated the documentUseful 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.

Custom field examples:

{{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.

Date formatting options
{{Opportunity.CloseDate | date: "MMMM d, yyyy"}} → June 15, 2026
{{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
Number and currency formatting
{{Opportunity.Amount | currency}} → $12,500.00
{{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.

Opportunity Products (line items) table
{REPEAT OpportunityLineItems}
{{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:

Fallback / default value
{{Contact.Title | default: "Representative"}} — shows "Representative" if Title is blank
{{Opportunity.Description | default: "N/A"}} — shows "N/A" if Description is blank
Conditional logic to hide entire sections
{IF Contact.Title != ""}
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

Field outputs blank unexpectedly

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.

Merge field appears as raw text

The field was typed incorrectly — check for mismatched curly braces, spaces inside the field name, or an incorrect object/field separator.

"null" appears in the document

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.

Related field not found

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

Yes. Salesforce formula fields are fully supported as merge fields in Dochly. They use the same syntax as standard fields — {{ObjectName.FormulaFieldAPIName__c}} — and output the calculated value at generation time.
Yes. You can use the same merge field as many times as needed in a template. Each instance will be replaced with the same value from the record at generation time.
Rich text fields are supported but output as plain text by default. The HTML formatting stored in the Salesforce rich text field is stripped on output. If you need formatted output from a rich text field, contact Dochly support for configuration options.
If there is no related Contact on the Opportunity, all Contact merge fields will output blank. Use conditional logic to hide Contact sections when no contact is present, or add a validation rule to require a contact before document generation can be triggered.

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

Dochly
Salesforce AppExchange — UTECH HUB Install Dochly on AppExchange

Rated 5 stars · Native Salesforce app · Free to install