I am trying to fetch the note title, note body as per the related contact ID in one SOQL query as two SOQL queries won't serve the purpose.
In contentNote, We have the note title and note body but don't have the contact information. For contact information, there is contentDocumentLink but contentNote don't share any direct relation with contentDocumentLink.
When I run the below SOQL query in the Developer Console
SELECT Id, Title, TextPreview FROM ContentVersion
WHERE ContentDocumentID IN (SELECT ContentDocumentId FROM ContentDocumentLink WHERE LinkedEntityId = '0030H000059CBKAQA4')
It throws below error:
ERROR at Row:2:Column:59 Entity 'ContentDocumentLink' is not supported
for semi join inner selects
below query also don't serve the purpose as contentDocument object has note title but don't have the note body.
SELECT ContentDocument.title FROM ContentDocumentLink WHERE LinkedEntityId
= '0030H000059CBKAQA4'
It is really frustrating to get all the details in one query, could someone please suggest if note title, body and contact id can be fetched in a single
query
Our purpose is to get all the data and integrate with another system.
Best Answer
There exists a relation between
ContentNote
andContentDocumentLink
. In order to get theContentNote
orContentVersion
, there are different ways of achieving it.Using 2 SOQL's
ContentDocumentLink
using theLinkedEntityId
i.e. in your case it will beContactIDs
and collect all theContentDocumentId's
.ContentDocumentID's
, you can query onContentNote
using theContentDocumentId's
retrieved from previous query.This is how your sample code should look like
Using relationship queries
ContentNote
details using relationship fields by querying onContentDocumentLink
object and filtering it withLinkedEntityId
Your sample code for that would be
In the above query, you can get the
ContentNote's
fields i.e.Title
andVersionData
along with itsLinkedEntityId
which would be yourContactId
You can refer the API document of Content Note for more information.