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
Marco ChoinièreMarco Choinière 

Strip HTML but keep line feeds

Hello,

I'm using an html template to reply to emails in salesforce. From what I have learned, when you create an html template and leave the text version blank, salesforce automatically copies the content of the htmlbody to textbody with a certain parsing process to strip the html code. In my template, I use the textbody field of the email message to put the content of the previous email.

The problem is that is a user replies to an email with my template, the text the user has written is stripped of all line feeds / carriage returns that he typed when it's copied to the textbody field. I can't use the htmlbody field in my template because I will have all the html markup as well as the text.

Is there a solution to this ? I'm trying to write a trigger that will copy the htmlbody to a custom field i created to control the parsing process myself but it seems complicated. In visualforce, we can use a "escape" attribute on certain apex tag that seems to do the job really well but I don't know how to use the same function in apex code.

Thanks your help.

Marco