Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Similar to how we can use apex to get the blob value of a VisualForce page, can we also do this on a VisualForce Email Template? We need to get the rendered template into an attachment record in Salesforce.

share|improve this question
Not sure about Email Template but for Visualforce Page we can . – Mohith Shrivastava Dec 4 '12 at 12:33
see: Summer 16 new feature here: – cropredy May 1 at 23:20

One approach might be to factor the bulk of your Email Template code (which of course is just VF markup anyway) into a Visualforce Component. Thus enabling you to share it by referencing this component between a Visualforce Page (to enable you to capture it on your attachments) and Email Templates (for when your emailing). For example.

<apex:component access="global">
  <apex:attribute name="targetObject" type="Test__c" description="The context of the outer page / email templates" access="global"/>
  <p>This is your new Component that is shared between your Email Template and Visualforce Page</p>
  <p>This is the name of your record {!targetObject.Name}</p>

Your email template would look like this...

<messaging:emailTemplate subject="Test" recipientType="User" relatedToType="Test__c">
    <messaging:plainTextEmailBody >
        <c:ShareComponent targetObject="{!relatedTo}"/>

Your VF page would look like this...

<apex:page standardController="Test__c">
    <c:ShareComponent targetObject="{!Test__c}"/>

Hope this helps!

Note: Note that Visualforce Components when delivered in Managed Packages are none editable, unlike Email Templates. You can work around this though, by copy and pasting the component code into a new one in the subscriber code and changing the template to point to the new component.

share|improve this answer

Select e.TemplateType, e.TemplateStyle, e.Subject, e.Name, e.Id, e.Body From EmailTemplate e

I tried this with this query .For Visualforce Email template I did not get anything in Body while for Text Template we get the body.

Hence i dont think it will be possible to extract data as blob for visualforce email template

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.