How can I fetch Notes data related to a specific Account using SOQL query in Salesforce?
I tried with the below SOQL query but it gives me empty rows.
SELECT Id, Title, Body FROM Note WHERE ParentId = '<Account_id>'
I am attaching a screenshot for better understanding.
I want to query the Notes which are marked in red color in the above image.
PS: Am new to Salesforce
Uh, bit tricky for first task :)
Note
is old object primarily used in old Salesforce UI, maybe you have heard of "classic" or "aloha". You are using new Lightning UI and the object you're looking for is ContentNote
.
Old: https://developer.salesforce.com/docs/atlas.en-us.object_reference.meta/object_reference/sforce_api_erd_documents.htm New: https://developer.salesforce.com/docs/atlas.en-us.object_reference.meta/object_reference/sforce_api_erd_contentnote.htm
To make matters bit messier ContentNotes are built on top of the solution for uploading Files, they're a special type of file. And that one is split into 2 tables - the header that can be linked to from many areas in the system (ContentDocument
), wasting space on disk only once... and actual payload which can be versioned (ContentVersion
)
Anyway: this should work
SELECT ContentDocument.Title, ContentDocument.LatestPublishedVersion.VersionData
FROM ContentDocumentLink
WHERE LinkedEntityId = '001...'
AND ContentDocument.FileType = 'SNOTE'
Another, simpler way would be to use a flatter, readonly view of all the "files" linked to the record (old school attachments, new files, stuff uploaded as Chatter posts, stuff cross-linked from SharePoint for example...). You'd have to experiment with CombinedAttachment
SELECT Name, (SELECT Title FROM CombinedAttachments)
FROM Account
WHERE Id= '001...'