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
Shweta GargShweta Garg 

Show Long Text Area content with Line break

Hi All,

I have created a visualforce email template.I need to show T_Last_External_Post__c (field in  Case object) on email template with line break.
Here is my code.
 
<messaging:emailTemplate subject="test" recipientType="Contact" relatedToType="Case"> <messaging:htmlEmailBody > <html> <body> <apex:outputText value="{!SUBSTITUTE(SUBSTITUTE(JSENCODE(relatedTo.T_Last_External_Post__c), '\r\n', '\n'),'\n','<br/>')}" style="white-space:pre;" /> </body> </html> </messaging:htmlEmailBody> </messaging:emailTemplate>


but it not working .
any help is much appreciated.
_Zach Boyd_Zach Boyd
Most likely the <br/> tags are being escaped by apex:outputText. Try setting escape="false" on apex:outputText like below
 
<apex:outputText value="{!SUBSTITUTE(SUBSTITUTE(JSENCODE(relatedTo.T_Last_External_Post__c), '\r\n', '\n'),'\n','<br/>')}" escape="false" style="white-space:pre;" />

Here is the reference to the apex:outputText attributes - https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_compref_outputText.htm
 
_Zach Boyd_Zach Boyd
One thing to note about my comment above. If the value in the field T_Last_External_Post__c is user submitted then not escaping the HTML could introduce a security risk if it included malicious javascript. You can read more about that in the link above, but I thought I would point that out. 
_Zach Boyd_Zach Boyd
Were you able to confirm if that worked for you? If so, could you please mark as correct so others can leverage in the future.