VisualForce Email Template

VisualForce email templates came as a part of winte ’09 release which leverages on VisualForce technology to provide underlying framework for email templates.

You need to know three tags to create VisualForce email template

1) <messaging:emailTemplate> – in which you specify recipient type, relatedToType, subject and email address that they can reply back to.

2) <messaging:htmlEmailBody> – in which you define the html content you want to show in your Email.

3) <messaging:plainTextEmailBody> – in which you include the text version of your Email.

Let me show you a simple example of how to create a VisualForce email template. We are going to create an email template which sends email about contacts that are related to an account.

The first step is to create an email template by going to Setup -> Administration Setup -> Communication Templates -> Email Templates -> New Template

<messaging:emailTemplate subject="Contact Information for Account: {!}" recipientType="Contact" relatedToType="Account" replyTo="">
<messaging:htmlEmailBody >
<p> Dear {!},</p>
<p> Below is the list of contacts related to your account: {!}.</p>
<table border="0">
<th> Action </th>
<th> Contact Name </th>
<th> Contact Email </th>
<apex:repeat var="con" value="{!relatedTo.Contacts}">
<td> <a href="{}"> View </a>
<a href="{}/e"> Edit </a> </td>
<td> {!con.Name} </td>
<td> {!con.Email} </td>
<messaging:plainTextEmailBody >
Dear {!},

Below is the list of Contacts related to Account: {!}.

[Contact Name] - [Contact Email]
<apex:repeat var="cont" value="{!relatedTo.Contacts">
[cont.Name]  -  [cont.Email]

For more detailed information login to


Last step is to test and verify merge fields. Click Send Test and Verify Merge Fields button to verify merge fields.




Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s