Useful Salesforce SOQL Queries

Salesforce Object Query Language (SOQL) is a powerful tool allowing you to retrieve specific data from Salesforce efficiently. It’s like SQL but optimized for Salesforce. With SOQL, you can query records, filter data with precision, and aggregate results to gain deeper insights into your org. Here are some useful Salesforce SOQL queries for reporting that isn’t easily available otherwise.

Files attached to Accounts
Get a list of contents within the Files related list for Accounts. (You can adapt for other objects by changing the object name.)

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 list of contents within the Files related list for Opportunities. (You can adapt for other objects by changing the object name.)

SELECT LinkedEntity.Name, ContentDocument.Id, ContentDocument.Title, ContentDocument.FileType
FROM ContentDocumentLink
WHERE LinkedEntityId IN (SELECT Id FROM Opportunity) ORDER BY LinkedEntity.Name

Permission Sets assigned to Users
Get a report on Users and Permission Sets they are assigned

SELECT Assignee.Name, PermissionSet.Label
FROM PermissionSetAssignment
WHERE PermissionSet.IsOwnedByProfile = FALSE
Scroll to Top