I am trying to insert text into a rich text area field which has string '\\n' in the text. However salesforce is ignoring everything after '\\n'. This is basically a chat transcript coming from another system and there are multiple instances of '\\n'. Appreciate any inputs.


For the rich text field you will need to use HTML equivalent of new line. You will have to replace the \n with br in your code.

Please try below:

String s = 'Test \n String';
s.replaceAll('\n', '<br/>');

Before inputting the data into that field, I would replace all occurrences of \\n with <br/>. Alternatively, you could enclose the data in <pre></pre> tags.

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