I have long text area field, which has data on each line. I am populating a line then hitting "Enter" and then populating the next line and hitting "enter" again and so on.

When reading this field from APEX I am splitting the field by \n


This returns me list of string where each string corresponds to the line in the long text area field. This way I am successfully able to read each line of the long text area field.

When I looked at the documentation of Long Text Area, below is what I see following:

Note that every time you press Enter within a long text area field, a linebreak and a return character are added to the text."

But based on what I explained in the begining when I press enter, all I get is a \n, newline character.

Why do I see difference in documentation vs what I am doing ? Is my way of reading Long Text Area field is correct or am I missing something ?

3 Answers 3


The documentation is correct. Ultimately, they are putting \r\n to represent a "new line". When you split the lines, you are looking only at \n. This will cause each line to start with \r and won't impact the way you are reading the string lines in your code.

Try this instead:

List<String> lines = rec.My_Long_Text_Area_Field__c.split('\r\n');
  • 1
    I looked at each character in the long text area and found that after each "enter" , \r and \n is added. I can split using \r\n and then it correctly gives me the each line of the text area. Order is \r and then \n. It is important to split by both \r and \n. just splitting by \n would leave \r at the end of the string. On the other hand, when reading the same field from SOAP API given only \n and no \r.
    – apn
    Sep 16, 2014 at 21:42

value="{!SUBSTITUTE(JSENCODE(textVariableThanContainsNewLines), '\r\n', ' ')}"

  • 1
    can you please give some details or explain your answer Jan 21, 2015 at 22:23

This would fix everything. No need to separately check for \r\n and bold or other characters.

<apex:outputText value="{!HTMLENCODE(item.Line_Description2__c)}" style="white-space:pre;" escape="false"/>

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .