I have a requirement where i need to copy the contents of a contentnote to a longtextarea field called 'comments' using apex anonymous.

The issue is i am getting the following HTML characters

for each line breaks in the body of the content note. I want to hide these

tags but at the same time maintain the linebreaks! enter image description here enter image description here

my code converts the blob to a string and also displays HTML characters:-

List<ContentNote> cntNoteList = [SELECT Id,content,TextPreview FROM 
ContentNote WHERE Id in :noteId];
  Map<Id, String> cntMap = new Map<Id, String> ();
     for(ContentNote cn : cntNoteList){

      string s1 = cn.content.tostring();
//string s2 = SUBSTITUTE(JSINHTMLCODE(s1),'\\\n','<br/>')
// string s2 = s1.replaceAll('\\\n', '<br/>');
  String s2 = s1.stripHtmlTags();
cntMap.put(cn.Id , s2);
  • 1
    Noticed that the same question being asked again, did you delete old one and created new one? Original question had a comment by sfdcfox asking to add more details. Such kind of activity is not nice to do. You should have patience and clarify the problem based on comments. – Raul Feb 19 '18 at 10:52

Thank u so much for ur comments! ButI have found the answer to my question. The linebreaks are removed now in a longtextarea field

 string s1 = cn.content.tostring();
   string s2 = s1.replace('<p>', ' ').replace('</p>','\r\n');  
     string s3 = s2.unescapeHtml4(); 

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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