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
Lee SinLee Sin 

Description field line break disappeared.

I am trying to query the standard 'Description' field of Opportunity and put it into an HTML table.(I am writing HTML email not VF page)
This field is a long text area field.

In the standard page layout, the text is separated by several line breaks.
But in my apex code, when I store it in a string, I can not find  '\r\n' in the string. 

Any ideas?
Thanks in advance.
Brenda S FinnBrenda S Finn
Lee

I believe the issue is that the text inside your text area is wrapping due to the size of the text area in the page layout and there are no hard line breaks. I just tried this and if you explicitly hit return inside your Description text area, the value of Description will contain the line breaks in the database. Check out this anonymous code (replace oppt id with your relevant opportunity id).
Opportunity oppt = [select Description from Opportunity where id='006n0000002D6RR' limit 1];

System.debug('=========> Description = \'' + oppt.Description + '\'');
System.debug('==========> Description does ' + 
(oppt.Description.contains('\r\n') ? '' : ' NOT ') + ' contain new line character.');

But your users are most likely not going to insert line breaks when entering content in Description field - they will just allow text to auto-wrap. So you need to work on formatting Description in your email template using HTML <br> and <p> tags but that could be tricky as length of description will be different for each Opportunity and the width/size of your email client window will vary. I would suggest leaving it alone in email body and just separate it from other text in the email with a few blank lines.

Hope this helps. Not sure what exactly you were looking for?