I am trying to convert a Long Text Area Field to a RTF but when I do so I loose all the formatting it just removes the HTML tags and makes the area a whole chunk. So what I am trying is instead of converting a Long Text Area in to RTF, I created a new field which is RTF and through Apex Trigger I am moving the content like below

 for (Knowledge__kav con : Trigger.new) {
      con.SOP_Article_Body__c = con.Article_Body_Long_T__c.unescapeHtml4();

where SOP_Article_Body__c is a RTF and Article_Body_Long_T__c is a Long Text Area. Even then I am not able to see the HTML tag/formatting being retained. Am I missing anything here

  • 1
    Please use edit and illustrate an example of the value inside Article_Body_Long_T__c
    – cropredy
    Commented Jun 16, 2020 at 4:44

1 Answer 1


To retain the formatted value of long text area while coping to the rich-text area, You need to replace all the carriage returns with br's as rich text area accepts HTML instead of a string.

I did something like this and it worked:-

Account__c acc= [SELECT Id, Name, Long_Text__c, Rich_Text__c FROM Account__c where id='a0WB0000000WrLUMA0'];
acc.Rich_Text__c = acc.Long_Text__c.replaceAll('\n', '<br/>');
update acc;

enter image description here

Reference:- https://developer.salesforce.com/forums/?id=906F000000092CAIAY

You must log in to answer this question.

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