In short
- Lightning templates use {{{Object.Field}}}. Classic templates use {!Object.Field}.
- The template's Related Entity Type decides which object's fields you can merge, custom objects included.
- A blank merge field means the field is empty, the wrong record is related, or the sender cannot see the field.
- Use formula fields for fallbacks and for values from parent records.
Salesforce email template merge field syntax
The syntax depends on the type of template. Use the Insert Merge Field button in the template editor and Salesforce writes it for you, which avoids typos.
- Lightning email templates: {{{Recipient.FirstName}}}, {{{Sender.Name}}}, {{{Organization.Name}}}, and fields from the related object, like {{{Opportunity.Amount}}}.
- Classic text, HTML and custom templates: {!Contact.FirstName}, {!User.Name}, {!Opportunity.Amount}.
- Visualforce templates: {!recipient.FirstName} for the person and {!relatedTo.Amount} for the related record.
Recipient works for leads and contacts alike, so a template can go to both. Merge fields from Contact only fill in when the recipient is a contact.
Merge fields from custom objects
To merge fields from a custom object, like an invoice or an admission, set the template's Related Entity Type to that object.
Create the template
In the Email Templates tab, create a Lightning template and choose the custom object as the Related Entity Type.
Insert the fields
Use Insert Merge Field and pick from the object, like {{{Invoice__c.Amount_Due__c}}}.
Send from the record
Send from that object's record, or set the email's Related To field to it, so Salesforce knows which record to read.
We have matched invoice email templates field by field to the Salesforce fields behind them. Write the list down: each merge field, its source field, and a record where it is filled in.
Why a merge field comes out blank
- The field is empty on that record. Check the record, not the template.
- The wrong record is related. The email's Related To points at another record, or at none.
- The recipient is the wrong type: a Contact merge field on an email to a lead.
- The sender cannot see the field. Field-level security applies to the person sending.
- A typo in a hand-typed merge field, or an API name that changed after the template was written.
- The field is on a parent record, like the account of a contact, that the template does not reach.
Talk through your project
A free call about your integration, your CRM or whatever you are stuck on. Honest advice, even if you never hire us. No obligation.
Use formula fields for fallbacks and parent fields
A formula field on the object can do what a merge field cannot, and the template merges it like any other field.
- Fallback text: a "Greeting Name" formula with BLANKVALUE(FirstName, "there") avoids "Hi ,".
- Parent values: a formula that reads Account.Phone or Owner.Email onto the record you send from.
- Formatting: dates and currency written the way you want them in the email.
Test merge fields before a send
Pick a real record
Use a record where every merged field is filled in, and one where some are blank.
Preview
Preview the template against each record, or send it to yourself.
Send as a user
Test as someone with the sender's profile, so field-level security is the same.
To make the right templates easy to reach, we have built an Email Templates button on the opportunity, so reps pick from the templates that fit that record. For sending to a list, see our bulk email guide.
Want help with this?
Book a free call about your CRM, integrations or reporting, or map your systems first with our free tech stack diagram builder.
