[SalesForce] SOQL Query getting Notes and Attachments from Custom Object

I am getting an error when executing the below query in the Developer Console:

select Id, Request_Title__c, 
(SELECT Id, Name FROM Attachments where id='a3K8E0000000BIj'), 
(SELECT Id, Title FROM Note where parentid='a3K8E0000000BIj') 
from Request_for_System_Change__c where id='a3K8E0000000BIj'

When I just run this it works:

SELECT Id, Title FROM Note where parentid='a3K8E0000000BIj'

But when I try to include the Notes alongside the attachments in my main query for my VF page, I get this error message:

ERROR at Row:3:Column:24
Didn't understand relationship 'Note' in FROM part of query call

So what's the correct way to include notes that have been added to a record in my Custom Object (Request_for_System_Change__c)?

Best Answer

You have to use the correct Relationship Name (Notes). Also you don't need to check for parentId condition again in the inner query..

select Id, Request_Title__c, 
(SELECT Id, Name FROM Attachments), 
(SELECT Id, Title FROM Notes) 
from Request_for_System_Change__c 
where id='a3K8E0000000BIj'
Related Topic