You need to sign in to do that
Don't have an account?
Scott Walker 73
Help displaying the HTML code saved in a long text field within a classic email template
Hi all
I am trying to work out a way to pull HTML code that gets saved in a long text record and use it to render a classic email template when that record is triggered to be used. If I paste the code in directly into the classic email template it works great but when called on as a field it doesn't work and displays as the raw HTML text. Does anyone have a way in which I could call on the HTML code saved in the field and use it to generate the email?
I am trying to work out a way to pull HTML code that gets saved in a long text record and use it to render a classic email template when that record is triggered to be used. If I paste the code in directly into the classic email template it works great but when called on as a field it doesn't work and displays as the raw HTML text. Does anyone have a way in which I could call on the HTML code saved in the field and use it to generate the email?
i think you need to create Visualforce Email template to render html code, use apex:outputText tag for field which has html code data.
Example :
<messaging:emailTemplate subject="Welcome" recipientType="Contact" relatedToType="Account">
<messaging:plainTextEmailBody >
Congratulations!
This is your new Visualforce Email Template.
</messaging:plainTextEmailBody>
<messaging:htmlEmailBody >
<html>
<body>
<apex:outputText value="{!relatedTo.description}" escape="false"/>
</body>
</html>
Thanks
All Answers
Is long text field type is rich text or text ? Rich text strips some of htmls chars which is not supported by it. please validate if queried html text field data is getting assigned to "html body" of the email.
I would recommand to store this html code in an actual html email template if Html email structure is not dynamic in structure(not data) by record and use it. You can perform better editing or formatting on html email body if it has been stored in an actual html email template.
Thanks
I have now made the field long text as that seems to make sense if the rich text strips some of the html characters.
Unfortunately the html code changes for each record so need to show it for each one every time from the record. I do not need to edit any of the html as thats done for me and all works great but can't display it when I call on it as a field within the classic email template. Any ideas how to make the code render correctly within a classic email template would be hugely helpful.
i think you need to create Visualforce Email template to render html code, use apex:outputText tag for field which has html code data.
Example :
<messaging:emailTemplate subject="Welcome" recipientType="Contact" relatedToType="Account">
<messaging:plainTextEmailBody >
Congratulations!
This is your new Visualforce Email Template.
</messaging:plainTextEmailBody>
<messaging:htmlEmailBody >
<html>
<body>
<apex:outputText value="{!relatedTo.description}" escape="false"/>
</body>
</html>
Thanks
Just tried this and after a bit of trail and error it has just worked a charm, really appreciate your help with this. Totally fixed our issue!