Useful Salesforce SOQL Queries

Here are some useful Salesforce SOQL queries for reporting that isn’t easily available otherwise.

Files attached to Accounts
Get a listing of the contents within the Files related list for Accounts.
SELECT LinkedEntity.Name, ContentDocument.Id, ContentDocument.Title, ContentDocument.FileType
FROM ContentDocumentLink
WHERE LinkedEntityId IN (SELECT Id FROM Account) ORDER BY LinkedEntity.Name

Files attached to Opportunities
Get a listing of the contents within the Files related list for Opportunities.
SELECT LinkedEntity.Name, ContentDocument.Id, ContentDocument.Title, ContentDocument.FileType
FROM ContentDocumentLink
WHERE LinkedEntityId IN (SELECT Id FROM Opportunity) ORDER BY LinkedEntity.Name

You can adapt the above for other objects by changing the bold object name above.

Scroll to Top