I have been trying to read all New Notes (richtext version) via SOQL query in Apex Controller class.

The design specifications for new notes signifies that they are stored in as ContentVersion records just like Files but with FileType='SNOTE'. I could query ContentDocumentLink to query all LatestPublishedVersionId of new SNotes but when I query ContentVersion object for those IDs, I get only the record Created/Owned by the logged in user, even though the Note is being auto shared because logged in user has Access to it via Parent Record, and I could see them in Notes and Attachments related list but not being able to query them via SOQL.

Any way I can bypass this?

EDIT: (test code attached - Looks like a Hard Coded limit is applied when reading New Beta Notes, they only are returning for creator of the notes and not for other users).

public without sharing class NotesBetaController {

    public NotesBetaController() {
        Id recId    = (Id) ApexPages.currentPage().getParameters().get('cid');
        this.readNotes( recId );

    private void readNotes(Id recId) {
        try {
            set<String> cdIds   = new set<String>();
            for (ContentDocumentLink cdl : [select Id, ContentDocumentId from ContentDocumentLink where LinkedEntityId =: recId and ContentDocument.FileType = 'SNOTE']) {
                cdIds.add( cdl.ContentDocumentId );
            string qry              = 'select Id, Title from ContentVersion where IsLatest=true and ContentDocumentId IN: cdIds and FileType=\'SNOTE\'';

            sObject[] obj = database.query( qry );
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.INFO, 'Total Notes: '+obj.size()));

            for (sObject s : obj) {
                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.INFO, 's: '+s));
        catch (Exception ex) {
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR, ex.getMessage()) );

Visualforce Page:

<apex:page controller="NotesBetaController">
   <apex:pageMessages />

Then Enable Notes in Setup:

enter image description here

Once enabled, open a Contact record. (using two separate user logins). Create a New Note from Notes & Attachment list. You should be able to see two Notes in the related list like this:

enter image description here

BUT in the Visualforce page I get only 1 record when opened from each user login:

enter image description here

I tried "with sharing" and "without sharing" APEX class keywords and BOTH return SAME result.

Is it a Hard-coded limit on SOQL fetching? The DOcumentation of Notes (beta) states that Richtext Notes are NOT Private, they are default shared based on Parent Record. It seems to be a bug/issue in api.

  • Guys does anybody have any idea on how to disable enforced sharing in SOQL queries? ... "without sharing" keyword isn't working in this case.
    – VarunC
    Commented Aug 18, 2015 at 20:37

1 Answer 1


You can retrieve all Notes for a parent record by querying on ContentDocumentLink and ContentNote objects.

A ContentDocumentLink record is created for each ContentNote entry. ContentDocumentId field in ContentDocumentLink object has a reference to ContentNote.

Here is the code to fetch all the SNotes related an account.

 public static List<ContentNote> getNotesForAccount(Id accountId) {
    List<ContentNote> contentNotes = new List<ContentNote>();
    List<ContentDocumentLink> contentDocumentLinks = [SELECT ContentDocumentId FROM ContentDocumentLink WHERE LinkedEntityId = :accountId];
    if (!contentDocumentLinks.isEmpty()) {
        Set<Id> contentDocumentIds = new Set<Id>();
        for (ContentDocumentLink contentDocumentLink : contentDocumentLinks) {
        contentNotes = [SELECT Id, Title, Content from ContentNote WHERE Id IN :contentDocumentIds];
    return contentNotes;

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .