[SalesForce] How to to use the lightning-formatted-rich-text LWC component to display Salesforce Base64 Notes (VersionContent)

Salesforce Note content is stored in ContentVersion.VersionData as Base64. The LWC lightning-formatted-rich-text just displays BLOB(n bytes).

The SOQL in Apex looks like this:

notesList = [select Id,Title,TextPreview,VersionNumber,CreatedBy.Name,CreatedDate,VersionData
    from ContentVersion
    where isLatest = true
    and ContentDocumentId = : noteIds
    and FileType = 'SNOTE'];

The template HTML looks like this:

<template for:each={notes.data} for:item="note">
    <p key={note.Id}>{note.Title}-{note.TextPreview}</p>
    <lightning-formatted-rich-text key={note.Id} value={note.VersionData}></lightning-formatted-rich-text>
</template>

I'm developing a custom Notes control (LWC) to provide better functionality/features. I'm currently using a wired Apex method, which is returning the correct List of records.

Because Salesforce uses Base64 for rich text storge and they have a rich text formatting component, it seems natural that there should be a built-in solution, but I'm finding no information in the developer documentation.

Best Answer

The Rich Text component expects an HTML and is what the Note Content actually has, but you just need to decode the base64.

base64Decode(content).toString();
Related Topic