You are here:
Use the Salesforce Merge Language in Classic Email Templates
Classic email templates use the Salesforce Merge Language (SML) only. Read these considerations for using SML.
Required Editions
In Summer ‘18, we introduced the Handlebars Merge Language (HML) for email templates in Lightning Experience. If your email template has merge fields with three curly braces ({{{), you’re using an HML email template. If the merge fields have one curly brace ({), or an exclamation mark (!), you’re using a SML (Salesforce Merge Language) email template. Lightning templates created since Summer ‘18 are HML email templates.
Guidelines for Syntax and Formatting
The syntax consists of an open curly brace and exclamation point, followed by the object name, a period, the field name, and a closing curly brace. For example, if you want to include the account number of your recipient, you could enter ID: {!Account.AccountNumber}, and your recipient's email displays ID: 001234567890123.
A merge field’s syntax can vary depending on where you're using the field. Most merge fields for email templates correspond directly with record fields.
To make sure you're using the correct syntax, select merge fields from the merge field picker.
Guidelines for Using Merge Fields
- General:
- Don’t use a hyperlink formula field in the subject of an email template or in the body of a text email template.
- In Classic email templates, you can add
substitute text to any merge field. Substitute text appears in a sent email if the merge
record does not contain data for that field. To add substitute text, place a comma after
the field name and enter the text before the closing bracket, for example:
Dear {!Contact.FirstName, Valued Customer}. When you save the template, the merge field appears in the template asDear {!BLANKVALUE(Contact.FirstName, "Valued Customer")}. In this example, if there is no information in the First Name field of the contact record, the email you create with your template begins with “Dear Valued Customer”. - User fields are also known as Sending User fields for administrators and users with the “Manage Users” permission. Use them in email templates when referencing the person sending the email.
- Administrators and users with the “Manage Users” permission can use Receiving User merge fields for email templates to reference the recipient of the email.
- Campaigns: Campaign member merge fields cannot be used with other types of merge fields in the same email template. For example, if you create an email template using a campaign member merge field and you want to include the title of the recipient, use {!CampaignMember.Title} instead of {!Lead.Title} or {!Contact.Title}.
- Cases:
- When account merge fields are included in an email template and this template is selected after a contact is added to the email To field, the account merge fields are populated from the contact's account, not the case's account.
- If you have enabled Email-to-Case or On-Demand Email-to-Case, you can create email templates that support agents can use to respond to case emails. These templates can include merge fields that display information from the original email in the response.
- Connection Finder: Custom email templates must contain the survey URL.
{!Contact.PartnerSurveyURL}is available as a contact merge field when creating templates. - Contacts: You can use custom Contact or Lead fields for merging, but only for documents generated from that field’s object. For example, a custom Contact field can only be used for templates for contacts.
- Leads: You can use custom Contact or Lead fields for merging, but only for documents generated from that field’s object. For example, a custom Lead field can only be used for templates for leads.
- Orders: Merge fields for products on orders in email templates aren’t supported.
- Workflow: To use merge fields from user records in email templates, select from these
merge field types:
- User Fields—Use these merge fields to represent the sending user. Merge fields named {!User.field_name} return values from the user record of the person who created or updated the record that triggered the workflow rule.
- Workflow Target User Fields—Use these merge fields only in email templates for workflow rules on the User object. Merge fields named {!Target_User.field_name} return values from the user record that was created or updated to trigger the workflow rule.
- Approval Process merge fields can be used in email templates, but not mail merge templates.
This release contains a beta version of workflow on the User object that is production quality but has known limitations. To provide feedback and suggestions, go to IdeaExchange.

