4

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

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 Aug 18 '15 at 20:37

Your Answer

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

Browse other questions tagged or ask your own question.