Visualforce Email Template
2:22 AMNormally we create email templates by navigating to Setup--> Communication Templates --> Email Templates .. Merge fields are used in these templates to display data...
To enable users to create flexible email templates, Visualforce Email templates was introduced.. You can create templates with extensive HTML and Visualforce coding so as to develop some really appealing and effective templates.. But there are some limitations when you create a visualforce email template.. Before going into the limitations let us create a simple template now..
Create a Visualforce Email template by navigating to
Setup --> Communication Templates --> Email Templates --> New Template
Select "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 Template
Select "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...
12 comments
Hi,
ReplyDeleteThanks a lot for such a nice article.
Just had a little doubton the relatedtotype object. Does it need to be the Relatedto object of the contact object(in case i am sending mail to contacts) or is it the related object of the object which is sending the mail? is it possible to do data binding with data from the apex controller class in a template?
Thanks in advance,
Nilakshi
🚨🚨 YOU EVER GOT SCAMMED, THEN YOU SHOULD READ THIS 🚨🚨🚨
DeleteYou could probably get your money back, and I said probably, This is because most scammers don't move the money to a bank account, most scammers move it to a crypto currency wallet or a local money saving platforms, this way they stay undetected and noticed by authorities.
What you have to keep in mind is, this crypto wallet can be reported or hacked into, and this is what we do.
WHO ARE WE⁉️ YOU MIGHT ASK❗❕❗❕
We are ⭐PYTHONAX⭐ a group of skilled and experienced internet and computer experts. We have refocused our work force into tracking down scammers and helping victims of scam recover their money, or what's left of it. Using our experience in transactions tracking and jail breaking, we can now guarantee scam victims an opportunity to recover their money.
There are so many ways to get scammed in the world we live in today, majority of this scams are internet based scam, one of the major disadvantages of the internet. Here are examples of scams we have dealt with and can help such victims to this scams as well-:
❌Cryptocurrency investments scammed victims.
❌Forex/Binary Option investments scam victims.
❌Buying and Selling scam victims.
❌Dating & Romance scam victims.
❌Loans scams victims.
❌Housing & Estate Investments Scam victims. E.t.c.
How services are simple and and a breakdown of each steps of the process we will take to help you get your money back would be explained and told to you, what we do isn't illegal, we try and follow the rules and make sure you aren't involved in any crime. You can choose to remain anonymous, your personal info wouldn't be required of you, all we need are infos regarding the scam, infos like-:
1️⃣ Total Amount of what you were scammed.
2️⃣ The type of scam you were involved in.
3️⃣ The means of Communication you used in communicating with the scammers. Eg, emails, numbers or social media handles......
4️⃣ Details of which you used to make payments and transactions ID.
Do not feel shy or ashamed or stupid, this scammers are really good at what they do, they make everything look so real and convince and very very real like the actual real stuff.
Use this emails below to contact us-:
PYTHONAXHELP@PROTONMAIL.COM
PYTHONAXSERVICES@PROTONMAIL.COM
We assure you of no form of judgmets or guilt, we are professionals and only want to help.
You could do it, if you put a Visual Force component into the template
ReplyDeletecan I force a 'recipient'?
ReplyDeleteI have done the same, but in email my values are not coming
ReplyDeleteMy email fields are empty, they don't show on the email. Any ideas why not?
ReplyDeleteSimple and nice one! Thanks alot
ReplyDeleteI have one question - Can I display or attach a document to this template. For example, if a user selects this template from the Opportunity > from Activity History section >> Send An Email button. Then the attachments which are in that Opportunity should be attached to that Email where this template is selected. Can we do this?
ReplyDeleteI have done the same, but in email my values are not showing in Email
ReplyDeleteI am receiving blank emails
ReplyDeleteThe emails being sent out from WorkFlow dont contain any data.
ReplyDeleteSame problem...no data coming from controller when I tried using a component in template
ReplyDelete