It seems to me that the markup inside of Salesforce richtext fields is somewhat stripped/trimmed when saving?

My code relies on the fact that an image has an multiline alt attribute (which is valid HTML. But whenever I save this fields record those multilines are removed.

Have you seen this before and how could I prevent this from happening? Use a long text field instead and output with outputText?

  • If you control the attributes, could 
 get you going? – bigassforce Jan 24 '13 at 22:53

Sadly I've tried a few things for you and I don't seem to be able to get this to work either. My conclusion and thus answer, agrees with your findings, newline characters in attributes are being stripped.

It appears as though a space is being replaced with any new line character/s.There is a lot of successful examples using text area, but not rich text area, by using \r\n. Anyway here is the code I was trying it out with in case you want to compare. Sorry I could not find a solution for you this time Robert.

Update: As per user31, I also tried &#13 and &#10 and combinations.

Update: The answer to this question goes someway to explain what I suspect is happening internally.


Markup put into these fields is cleansed internally I believe to provide as much protection as possible from XSS attacks which could be implemented through HTML in these fields which then gets inserted into the page on render.

If you need some way of indicating a line break I'd use a custom code of your own devising, something unlikely to appear int he alt-text otherwise, for example CRLF. You could then perform a search and replace after querying the field to put in whatever line breaks you need.


I switched to long text fields and used my own richtext editor on them (CKEditor) and now it works. Long text fields work as a charm without the problems they imposed on RTF fields for security reasons.

Thanks for your answers.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.