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
AbiPatAbiPat 

Trouble Using HTML Data From the Rich Text Editor

I am trying to grab the data stored in a rich text field in its HTML format, and send it via a REST API callout. I noticed that the rich text editor adds tags like <span>, which are irrelevant and unneccesary, and it also adds the 'style' attribute to the <br> tag (ie <br style="">). Lastly, it also adds newlines using \n when I print the html output using system.debug(). [I dont see the '\n', but I can see the string broken into multiple lines in system.debug()].
Has anyone faced this issue, and are there any ways getting around this? Happy to provide details if needed.
James LoghryJames Loghry
You're going to get junk data in those fields no matter what.  You can try parsing out the \n's and styles on the <br> tags, but you're going to spend a lot of time figuring out all the different cases that could go wrong in rich text fields.  One option is to a regex, as mentioned here: http://salesforce.stackexchange.com/questions/32049/how-to-retrieve-just-the-text-without-formatting-from-a-rich-text-field-using-js
AbiPattyAbiPatty
Thanks James! 
I guess I ll have to follow the former approach - ie parse out the \n's etc - as I want to remove only the improperly formed html tags, so that rules out the regex. Hopefully the editor will get better and more reliable with future releases!