function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Nathan MarchantNathan Marchant 

How to write SOQL query with two objects

Hi,

I need to write this as one single query as i need to display this information inside one table on visualforce.
Basically I need to

find name of document and ContentDocumentId from ContentDocumentLink  where LinkedEntityId equals an accountid for example "0016E00000ZdEEdQAN"

now in the same query i wish to find DistributionPublicUrl from ContentDistribution where ContentDocumentId  equals ContentDocumentId we found this value in the first part of the query.

I have managed to get these two querys working seperatly in my apex my using a variable to save the ContentDocumentId

here are my seperate versions:
CDRecords =[SELECT ContentDocumentId, ContentDocument.title FROM ContentDocumentLink WHERE LinkedEntityId = '0016E00000ZdEEdQAN' ALL ROWS];
CDId = CDRecords[i].ContentDocumentId;
[SELECT DistributionPublicUrl FROM ContentDistribution WHERE ContentDocumentId =:CDId]

Here is my attempt at doing one query. Im not really sure how to do this. if anyone can help me out that would be great!


SELECT ContentDocument.title
   (SELECT DistributionPublicUrl FROM ContentDistribution WHERE ContentDocumentId = ContentDocumentLink.ContentDocumentId) FROM ContentDocumentLink WHERE LinkedEntityId = '0016E00000ZdEEdQAN'
Dushyant SonwarDushyant Sonwar
Hi Nathan ,

I don't see any direct relationship with contentdocumentlink to ContentDistribution .
User-added image


Also Salesforce does not support relationship for contentDocument or ContentVersion for SOQL.

So your separate version is the only way to get contentdistribution.