We are migrating from Classic to Lightning, In this process we are converting classic Notes to Lightning supported Note (ContentVersion). We have a batch which does this job, getting below error:
UNSAFE_HTML_CONTENT, Note can't be saved because it contains HTML tags or unescaped characters that are not allowed in a Note.: [VersionData]
I am using below snippet for escaping html characters, Please let me know if you have faced the similar challenges while doing so:
String noteBody= noteBody<ClassicNoteBody>.replace('&', 'sfdcAMPERSANDsfdc').escapeXml().replace('sfdcAMPERSANDsfdc', '&').replace(''', ''').replace('©', '©').replace('<','<').replace('>','>').replace('\'',''').replace('"','"').replace('\r\n', '<br>').replace('\r', '<br>') .replace('\n', '<br>');
ContentVersion cv = new ContentVersion();
cv.versionData = Blob.valueOf(noteBody);