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
GoForceGoGoForceGo 

Adding Line return to a Long Text Field

How does one do it?


Adding \n or \r does not work.

 

Object.Long_Text_Field__c = 'xyz' + '\n'  + 'abc'

 

 

Best Answer chosen by Admin (Salesforce Developers) 
Ernie82Ernie82

The way to get it to show in the UI correctly is to use the html line break:  <br>

 

so:

  Object.Long_Text_Field__c = 'xyz' + '<br>'  + 'abc'

 

Showed in the detail page as:

 

xyz

abc

 

AND when I edit the record or the individual field it shows as:

 

xyz

abc



 

This should resolve your issue all together.

All Answers

Ernie82Ernie82

I was working on the same thing, and found that the \r did actually work, but in the regular UI, it did not wrap the text, but when I opened the field for edit, the carriage return was there and it did in fact work.

 

so:

  Object.Long_Text_Field__c = 'xyz' + '\r'  + 'abc'

 

Showed in the detail page as:

 

xyzabc

 

but when I edit the record or the individual field it shows as:

 

xyz

abc

 

GoForceGoGoForceGo

Thanks....

 

I wonder if there is a way to make it the way it looks in standard salesforce.

 

 

Ernie82Ernie82

The way to get it to show in the UI correctly is to use the html line break:  <br>

 

so:

  Object.Long_Text_Field__c = 'xyz' + '<br>'  + 'abc'

 

Showed in the detail page as:

 

xyz

abc

 

AND when I edit the record or the individual field it shows as:

 

xyz

abc



 

This should resolve your issue all together.

This was selected as the best answer
GoForceGoGoForceGo

Yes indeed it would. Let me try it...thanks.