Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
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.

share|improve this answer

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.

share|improve this answer
up vote 2 down vote accepted

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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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