function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Aaron HillAaron Hill 

Fields that are populated with html text, as merge fields in visualforce emails

I have a large text field on Opportunities that is populated with text formatted by html when the Opportunity is created. I use an apex trigger to do this. The field is a simple questionnare asking details about the opportunity the. The trigger only inserted html code into the field, nothing too fancy.

I created a visualforce email template with the field inside of it hoping I could send a copy of the questionnare to my team. I put the merge field inside of html tags. But when I tested the template my merge field rendered as plain text, with no line breaks, and all of the html tags. 

Here is the visualforce template:
 
<messaging:emailTemplate subject="RTF Email template" recipientType="User"
relatedToType="Opportunity"
 >

<messaging:htmlEmailBody >
<html>
    <h2><em>Hello! I'm a rich text email! And the general project details for this oppy are:</em></h2><br></br><br></br>
    {!relatedTo.General_Project_Details__c} c
    
    <br></br><br></br>
    <p style="{font-size: 32px; color:purple}">Look how rich I am!!!</p>
    
    <div style="border:1px solid green"><p style="font-size: 46px; color: red">I'm the richest text ever!</p></div>
</html>




</messaging:htmlEmailBody>
</messaging:emailTemplate>


And the resulting text looked like this:

User-added image


Normally I would use jQuery to re-encode the html. I saw something about using this command: 
!HTMLENCODE(myobjdata). 

But I've heard I can't use or shouldn't use jQuery in a visualforce email template.

I need that code to render! Can anyone help? Thanks!
Best Answer chosen by Aaron Hill
pconpcon
Try using apex:outputText instead.  You can tell it not to escape your HTML
 
<apex:outputText value="{!relatedTo.General_Proejct_Details__c}" escape="false" />

All Answers

pconpcon
Try using apex:outputText instead.  You can tell it not to escape your HTML
 
<apex:outputText value="{!relatedTo.General_Proejct_Details__c}" escape="false" />
This was selected as the best answer
Aaron HillAaron Hill
That worked, thanks!