How would I query the ContentNotes of an opportunity? I'm able to query all the ContentDocumentLink and able to get the ContentDocument but the ContentDocument does not have the fields that I'm looking for, mainly body or content.

  • 1
    because ContentVersion (which is where the actual body data resides) can support GB files, you can run into heap issues so you may need to revisit your design to ensure you won't hit these limits
    – cropredy
    Aug 30, 2016 at 2:05

2 Answers 2


The link between ContentNote and any related record is stored in the ContentDocumentLink. So, if you're writing a trigger or Executing Anonymous Code, you need to query all ContentDocumentLinks related to your Opportunity. So, something like this:

Map<Id,List<ContentNote>> noteMap = new Map<Id,List<ContentNote>>();

    for(ContentDocumentLink links : [SELECT LinkedEntityId, ContentDocumentId FROM ContendDocumentLink WHERE LinkedEntityID = '006xxOppId']){
        List<ContentNote> notes = noteMap.get(links.LinkedEntityId);
        if(notes == null){
            notes = new List<ContentNote>();
            noteMap.put(links.LinkedEntityID, notes);


This gives you a map of all ContentNotes for whatever Opportunity it is that you're indicating. Then you could loop over the list to do whatever it is that you're wanting to do.

    for(ContentNote cn : noteMap.get('Enter your oppId here'){
      //do something with your note records

You have to query ContentNote object. Here is the schema for ContentNote Objects:

ContentNote Objects

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.