Common SOQL patterns for querying Salesforce files
SELECT Id, Title, ContentDocumentId, FileExtension, ContentSize, CreatedDate FROM ContentVersion WHERE IsLatest = true ORDER BY CreatedDate DESC LIMIT 100
SELECT Id, Title, ContentDocumentId, CreatedDate FROM ContentVersion WHERE IsLatest = true AND CreatedDate = LAST_N_DAYS:30 ORDER BY CreatedDate DESC
SELECT Id, Title, ContentDocumentId, FileExtension FROM ContentVersion WHERE IsLatest = true AND FileExtension = 'pdf' LIMIT 500
SELECT Id, Title, ContentDocumentId, ContentSize FROM ContentVersion WHERE IsLatest = true AND ContentSize > 10485760 ORDER BY ContentSize DESC LIMIT 100
SELECT Id, Name, BodyLength, ParentId, CreatedDate FROM Attachment WHERE CreatedDate = LAST_N_DAYS:90 ORDER BY CreatedDate DESC LIMIT 200
SELECT Id, Name, BodyLength, CreatedDate FROM Attachment WHERE Name LIKE '%.pdf' ORDER BY CreatedDate DESC LIMIT 500
Was this page helpful?