Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

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 Kumar Dec 4 '12 at 12:33
add comment

2 Answers

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"/>
  <h1>Congratulations</h1>
  <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>
</apex:component>

Your email template would look like this...

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

Your VF page would look like this...

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

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
add comment

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
add comment

Your Answer

 
discard

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.