Search code examples
salesforceapexsoql

How to retrieve ContentNotes information along with LinkedEntity's information with SOQL?


I would like to implement a service that takes a lastModifiedDate as input and returns all ContentNote records which were modified after the given lastModifiedDate. The service response should have the following fields

  1. ContentNote:
  • Id
  • Title
  • Content
  1. ContentVersion
  • VersionNumber
  1. Account (LinkedEntity)
  • Id
  • Zipcode

Is there a way to implement this with as few queries as possible?


Solution

  • Notes are just content documents ("Files") with special type. This might give you some ideas?

    SELECT Id, Title, LatestPublishedVersion.VersionNumber, LatestPublishedVersion.VersionData,
    (SELECT LinkedEntityId, LinkedEntity.Name FROM ContentDocumentLinks)
    FROM ContentDocument
    WHERE FileType = 'SNOTE'
    AND LastModifiedDate = LAST_N_DAYS:7