Understanding Note and ContentNote Objects in Salesforce

Understanding Note and ContentNote Objects in Salesforce

Understanding Note and ContentNote Objects in Salesforce

Salesforce provides powerful tools for managing documentation and collaboration, with the Note and ContentNote objects being two key entities. Though they may seem similar at first glance, each serves unique purposes and offers distinct functionality. This article explores their definitions, key fields, differences, and methods to create them.

What are Note and ContentNote Objects?

Note Object

The Note object is part of the legacy "Notes and Attachments" feature in Salesforce. It is used to store unstructured text content that users can attach to records for additional context or documentation.

ContentNote Object

The ContentNote object represents a new and enhanced type of note introduced with the "Enhanced Notes" feature. ContentNotes are Salesforce Files with rich-text capabilities, collaborative features, and better integration with other Salesforce functionalities.

Important Fields

Note Object

  • Id: Unique identifier for the note.
  • Title: The title of the note.
  • Body: The main text content of the note.
  • ParentId: The ID of the parent record to which the note is linked (e.g., Account, Opportunity).
  • OwnerId: The ID of the user who owns the note.
  • IsPrivate: Indicates whether the note is private.

ContentNote Object

  • Id: Unique identifier for the note (as a file).
  • Title: The title of the note.
  • Content: The rich-text content of the note.
  • ContentDocumentId: The ID linking the note to its file entry.
  • OwnerId: The ID of the user who created the note.
  • IsArchived: Indicates if the note is archived.
  • RelatedEntityId: The ID of the primary record associated with the note.
  • SharingType: Specifies the sharing settings (e.g., Viewer, Collaborator).

Key Differences

Feature Note Object ContentNote Object
Storage Type Legacy Notes and Attachments Salesforce Files
Rich Text Not supported Supported
Sharing Limited sharing capabilities Granular sharing options
Collaboration Not collaborative Collaborative (multiple users)
Searchable Searchable via global search Enhanced search with file support
Parent Linking Single parent record per note Can relate to multiple records
API Name Note ContentNote

Creating Notes

Creating a Note (Legacy)

You can create a Note object programmatically or manually:

Manually:

  1. Navigate to the record you want to attach the note to.
  2. Click on the Notes & Attachments related list.
  3. Click New Note.
  4. Enter the title and body, and save.

Using Apex:

Note note = new Note();
note.Title = 'Important Note';
note.Body = 'This is the body of the note.';
note.ParentId = '001XXXXXXXXXXXXXXX'; // Replace with the record ID
insert note;

Creating a ContentNote (Enhanced)

Manually:

  1. Navigate to the Files tab or the Notes related list.
  2. Click New Note.
  3. Use the rich-text editor to create the content.
  4. Save the note, and relate it to a record if needed.

Using Apex:

ContentNote note = new ContentNote();
note.Title = 'Enhanced Note';
note.Content = Blob.valueOf('This is the body of the enhanced note.');
insert note;

// Link the ContentNote to a record using ContentDocumentLink
ContentDocumentLink link = new ContentDocumentLink();
link.ContentDocumentId = note.Id; // Use the ID of the inserted ContentNote
link.LinkedEntityId = '001XXXXXXXXXXXXXXX'; // Replace with the record ID
link.ShareType = 'V'; // Viewer access
link.Visibility = 'AllUsers';
insert link;

When to Use Note vs. ContentNote

Use Note if your organization is using legacy Notes & Attachments and doesn’t require advanced features like collaboration or rich-text editing.

Use ContentNote if you need enhanced features such as rich-text formatting, sharing, and integration with Salesforce Files.

Conclusion

While both the Note and ContentNote objects serve the purpose of attaching documentation to records, ContentNote is the preferred choice for modern Salesforce implementations due to its advanced features and better integration capabilities. Migrating from legacy Notes to Enhanced Notes can improve user experience and collaboration in your organization.

Comments

Popular posts from this blog

OOPS in Apex

System administrator gets logged out when they use 'Login as User'