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
sia thiripo 1sia thiripo 1 

SOQL for getting only files related accounts ?

I need a help for getting only the files containing accounts have to be sorted in list.
The accounts do not having files are not sorted in the list.

Thanks in advance
VinayVinay (Salesforce Developers) 
Hi Sia,

Try below
 
Select ContentDocumentId, LinkedEntityId  FROM ContentDocumentLink where LinkedEntityId in ( SELECT Id FROM Account ) and LinkedEntity.Type='Account'

Thanks,
sia thiripo 1sia thiripo 1
Hi Vinay,
I needed the list of Account names containing Files.

Thanks,
AnudeepAnudeep (Salesforce Developers) 
You will have to query on ContentDocumentLink only. Here are examples
SELECT ContentDocumentId FROM ContentDocumentLink WHERE LinkedEntityId = '<Opportunity or other object id here>'
 
SELECT ContentDocumentID, LinkedEntity.Name, ContentDocument.Title
FROM   ContentDocumentLink 
WHERE  LinkedEntityId IN
  (SELECT ID FROM Account 
  WHERE   Type = 'Active Partner (signed contract)' 
  OR      Type = '2-Tier Partner')
 
SELECT ContentDocumentId, LinkedEntityId  FROM ContentDocumentLink where LinkedEntityId in ( SELECT Id FROM Case ) and LinkedEntity.Type='Case'