Create a Visualforce Email template by navigating to
Setup --> Communication Templates --> Email Templates --> New TemplateSelect "Visualforce" in the first step...
Give a tilte,name,Subject for your template. Next select the Receipent type and Related to (Related to denotes the object from which you would want data to be displayed in your Email).. Click "Save".... Remember to check "Available for use" to make your email template available for use in Workflow email alerts and whereever it may be useful....
Setup --> Communication Templates --> Email Templates --> New TemplateSelect "Visualforce" in the first step...
Give a tilte,name,Subject for your template. Next select the Receipent type and Related to (Related to denotes the object from which you would want data to be displayed in your Email).. Click "Save".... Remember to check "Available for use" to make your email template available for use in Workflow email alerts and whereever it may be useful....
You will now see the template detail Page... In the "Email template" section click on "Edit Template" button... This will take you to a Visualforce Page editor...
You can also click on "Attach file" button in "Standard Attachments" section to attach a file from your desktop to your email..
Below is a small piece of code... You will have to put this code in the editor that appears when you click on "Edit template" button
Note: I have used "htmlEmailBody" for including HTML tags in my template.. Also, since the "Relatedto" is "Account" i am displaying Account information in my template..
You can also click on "Attach file" button in "Standard Attachments" section to attach a file from your desktop to your email..
Below is a small piece of code... You will have to put this code in the editor that appears when you click on "Edit template" button
Note: I have used "htmlEmailBody" for including HTML tags in my template.. Also, since the "Relatedto" is "Account" i am displaying Account information in my template..
<messaging:emailTemplate subject="Testing Visualforce Email Template" recipientType="User" relatedToType="Account"> <messaging:HtmlEmailBody > Account Name : {!Relatedto.Name} <br/> Account Description : {!Relatedto.Description} <br/> </messaging:htmlEmailBody> </messaging:emailTemplate>
What you Can...
With Visualforce email templates you can display any data from the related object in any format you wish.. If Relatedtotype =Account you can display any field of the Account and you can also display the related lists of Account .. For ex you can create a datatable with the value="{!Relatedto.Contacts}"... Similarly you can display other related lists...
What you Cannot...
You cannot use the <apex:page> tag inside your Email template.. Having said this you cannot use pageblock, pageblocksection or any other tag which is a child of the <apex:page> tag.. You can use outputfield,outputtext,datatable etc.. Do not attempt too much of styling and formatting for your email templates unless it is extremely necessary because you would'nt know how your email would be rendered by different providers.. Always use simple and standard formatting so that your email displays uniformly across all providers...
No comments:
Post a Comment