Salesforce Dictionary - Free Salesforce GlossarySalesforce Dictionary
DictionaryMMerge Field
Core CRMIntermediate

Merge Field

A Merge Field in Salesforce is a placeholder syntax used in formulas, email templates, validation rules, formula fields, Visualforce pages, and many other Salesforce surfaces to inject dynamic record data at runtime.

§ 01

Definition

A Merge Field in Salesforce is a placeholder syntax used in formulas, email templates, validation rules, formula fields, Visualforce pages, and many other Salesforce surfaces to inject dynamic record data at runtime. The syntax wraps a field reference in curly braces and an exclamation point: {!Account.Name}, {!Opportunity.Amount}, {!Contact.Email}. When the platform processes the surface (renders an email template, evaluates a formula, runs a Visualforce page), it replaces each merge field with the actual field value from the relevant record.

Merge fields are the primary mechanism for personalization across every Salesforce template-driven feature. Email templates use merge fields to address the recipient by name; Visualforce email templates use the same syntax inside Apex-rendered emails; formula fields use merge fields to reference parent-record values; validation rules use them in their criteria expressions. The exact merge-field syntax varies slightly across surfaces (formulas use FIELDNAME, email templates use {!FIELDNAME}, Visualforce uses {!FIELDNAME}), but the underlying concept is consistent: insert dynamic data at render time.

§ 02

Merge Field syntax across Salesforce surfaces

The {!Field} syntax

The Lightning-era merge field syntax uses {!FIELD_API_NAME} for direct fields and {!OBJECT.FIELD_API_NAME} for cross-object references. Examples: {!Account.Name} pulls the account name; {!Opportunity.Amount} pulls the opportunity amount; {!User.FirstName} pulls the current user''s first name. The syntax is consistent across email templates, Visualforce, Lightning, and most other template surfaces.

Cross-object references

Merge fields can traverse object relationships. {!Opportunity.Account.Name} pulls the account name of the opportunity''s account; {!Case.Contact.Email} pulls the email of the case''s primary contact. The traversal works through lookup and master-detail relationships up to five levels deep, the same depth supported by SOQL relationship queries.

$User, $Organization, $System globals

Beyond record fields, Salesforce supports global merge variables: $User for the running user ({!$User.FirstName}), $Organization for org-level info ({!$Organization.Name}), $System for system constants ({!$System.OriginDateTime}). These globals are available in formulas, email templates, and Visualforce, providing session and org context without explicit lookup.

Merge fields in email templates

Email templates make heavy use of merge fields. Classic email templates use {!FIELD_API_NAME} syntax. Lightning Email Templates use the same syntax with richer formatting options. Templates fail silently when the merge field doesn''t resolve (returning empty), so designers must test with real records to catch missing values.

Merge fields in formulas and validation rules

Formulas reference fields directly without the {!} wrapper: FirstName, Account.Name, Opportunity.Amount. Validation rules use the same direct syntax in their formula expressions. The {!} wrapper is for surfaces that mix merge fields with other content (templates, Visualforce, Lightning markup); pure formulas don''t need it.

Merge fields in Visualforce

Visualforce pages reference merge fields with {!} for expressions: <apex:outputText value="{!Account.Name}"/> renders the account name. Visualforce expressions can be more complex than simple field references, supporting Apex method calls and formula-like calculations. The merge-field syntax is the foundation but Visualforce expressions add power on top.

Merge field failures and null handling

Merge fields that point to null or missing values render as empty strings in most surfaces. Some surfaces have special behavior: formulas can use BLANKVALUE() or NULLVALUE() to provide defaults; email templates can use IF() to conditionally include text. The default empty-string behavior can produce broken-looking output (Dear , when First Name is null); careful template design avoids this.

§ 03

Use Merge Fields in an email template

The most common use of merge fields is personalizing email templates. The pattern is the same across Classic and Lightning email templates.

  1. Open the email template editor

    Setup, Communication Templates, Email Templates (Classic) or Lightning Email Templates (Lightning). Create or edit a template.

  2. Pick the related object

    The template targets a source object (Contact, Lead, Opportunity). The merge fields available depend on this choice.

  3. Insert merge fields

    Use the merge-field picker (typically a dropdown or toolbar button). Pick the field; the editor inserts {!FIELD_API_NAME}.

  4. Test with a sample record

    Send a test email to yourself targeting a real record. Verify every merge field resolves correctly.

  5. Handle null values gracefully

    For fields that might be null (middle name, suffix), wrap in IF() or BLANKVALUE() to avoid broken-looking output.

  6. Save and activate

    Save the template. Activate it for production use. Train users to pick the right template per scenario.

Mandatory fields
Source objectrequired

The object whose fields are available as merge fields.

Merge field syntaxrequired

{!FIELD_API_NAME} or {!OBJECT.FIELD_API_NAME}.

Cross-object traversalrequired

Up to five levels through lookup relationships.

Null handlingrequired

Use IF() or BLANKVALUE() to handle missing values.

Gotchas
  • Merge fields fail silently on null. Test with real records to catch broken output.
  • Cross-object traversal is capped at five levels. Beyond that, restructure the data model or use Apex.
  • The merge-field syntax varies slightly across surfaces. Formulas use direct field names; templates and Visualforce use {!}; check the surface-specific documentation.
  • Lightning Email Templates and Classic Email Templates use the same syntax but render differently. Test in both contexts when migrating.
§

Trust & references

Sources

Cross-checked against the following references.

Official documentation

Straight from the source - Salesforce's reference material on Merge Field.

Keep learning

Hands-on resources to go deeper on Merge Field.

Was this entry helpful?
Help us write better definitions. Quick reactions or detailed edit suggestions.

About the Author

Dipojjal Chakrabarti is a B2C Solution Architect with 29 Salesforce certifications and over 13 years in the Salesforce ecosystem. He runs salesforcedictionary.com to help admins, developers, architects, and cert/interview candidates sharpen their fundamentals. More about Dipojjal.

§

Test your knowledge

Q1. What is a Merge Field?

Q2. Where are merge fields used?

Q3. Is the syntax the same everywhere?

§

Discussion

Loading…

Loading discussion…