function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
VarunCVarunC 

Why Notes (Beta) not accept default Parent record sharing permissions when read using SOQL in APEX?

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 queried 'ContentDocumentLink' for 'LinkedEntityId' and retrieved ContentDocumentId to query all new SNotes but when I query 'ContentVersion' object for those IDs, I got 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.

(test code below):

APEX Class:
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 />
</apex:page>



Then Enable Notes in Setup:

User-added image


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:

User-added image


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

User-added image

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.