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', '&amp;').replace('&apos;', '&#39;').replace('©', '&copy;').replace('<','&lt;').replace('>','&gt;').replace('\'','&#39;').replace('"','&quot;').replace('\r\n', '<br>').replace('\r', '<br>') .replace('\n', '<br>');
ContentVersion cv = new ContentVersion();
cv.versionData = Blob.valueOf(noteBody);
  • is it possible to have more then one of any special character?
    – kurunve
    Oct 22, 2019 at 10:48
  • Yes, It is possible. replace(target, replacement) Replaces each substring of a string that matches the literal target sequence target with the specified literal replacement sequence replacement. Reference: developer.salesforce.com/docs/atlas.en-us.apexcode.meta/…
    – RKM
    Oct 22, 2019 at 11:01


Your Answer

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