function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Benjamin BogartBenjamin Bogart 

Include HTML or VisualForce page in email template

Hello,

Is it possible to include a visualforce (or HTML) page in a visualforce email template?

The use case is I have a set of data that changes, but needs to be appended to several different kinds of emails.  I would like to keep this data in a single visualforce page which I can update only once, and automatically include it at the end of the various other email templates I create.  

(I new here).  Thanks for the help.
Best Answer chosen by Benjamin Bogart
Nithesh NNithesh N
Yes, You can. 
First, Create a Visualforce Component Instead of Visualforce Page. 
Example: Component Name - awesomeComp
<apex:component>
    <apex:attribute name="record" description="The type of record we are viewing."
                    type="Object" required="true"/>
                     
    <apex:pageBlock title="Viewing {!record}">   
        <apex:detail />
    </apex:pageBlock>
</apex:component>
You can learn more about components Here. https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_comp_cust_def.htm

Then you can create Your visualforce email template and add it to the template.
<messaging:emailTemplate 
 subject="Hey there!">

<messaging:HtmlEmailBody >


<html>
<head>
<meta content="text/css;charset=utf-8" http-equiv="Content-Type"/>
<meta name="Template" content="Response"/>
</head>
<body>
<p><b>Your data</b>

<c:awesomeComp record="" />    // your Component.

</p>
</body>
</html>
</messaging:HtmlEmailBody>
</messaging:emailTemplate>

Best,
Nithesh

All Answers

akschampakschamp
Hi Benjamin,

You can give a try using Visualforce email templates where you can add reusable VF component (this component will contain the data)

Thanks!
Nithesh NNithesh N
Yes, You can. 
First, Create a Visualforce Component Instead of Visualforce Page. 
Example: Component Name - awesomeComp
<apex:component>
    <apex:attribute name="record" description="The type of record we are viewing."
                    type="Object" required="true"/>
                     
    <apex:pageBlock title="Viewing {!record}">   
        <apex:detail />
    </apex:pageBlock>
</apex:component>
You can learn more about components Here. https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_comp_cust_def.htm

Then you can create Your visualforce email template and add it to the template.
<messaging:emailTemplate 
 subject="Hey there!">

<messaging:HtmlEmailBody >


<html>
<head>
<meta content="text/css;charset=utf-8" http-equiv="Content-Type"/>
<meta name="Template" content="Response"/>
</head>
<body>
<p><b>Your data</b>

<c:awesomeComp record="" />    // your Component.

</p>
</body>
</html>
</messaging:HtmlEmailBody>
</messaging:emailTemplate>

Best,
Nithesh
This was selected as the best answer
Benjamin BogartBenjamin Bogart
This looks great!  Thanks both of you.

But I wonder, is there a way to use an html child theme in an email template instead of using a visualforce template.  For this application standard email template merge fields will be sufficient.  I don't need any business logic or data lookups, but I might need to use the component in a mass mailing at some point which is not available on visualforce templates.

Thanks!
HNT_NeoHNT_Neo
Will this trigger the html tracking found in the contact object which tracks the email send and email open rates?