Skip to main content

Basic File Queries

All Recent Files (Latest Versions Only)

SELECT Id, Title, ContentDocumentId, FileExtension, ContentSize, CreatedDate
FROM ContentVersion
WHERE IsLatest = true
ORDER BY CreatedDate DESC
LIMIT 100

Files from Last 30 Days

SELECT Id, Title, ContentDocumentId, CreatedDate
FROM ContentVersion
WHERE IsLatest = true
  AND CreatedDate = LAST_N_DAYS:30
ORDER BY CreatedDate DESC

PDFs Only

SELECT Id, Title, ContentDocumentId, FileExtension
FROM ContentVersion
WHERE IsLatest = true
  AND FileExtension = 'pdf'
LIMIT 500

Large Files (>10MB)

SELECT Id, Title, ContentDocumentId, ContentSize
FROM ContentVersion
WHERE IsLatest = true
  AND ContentSize > 10485760
ORDER BY ContentSize DESC
LIMIT 100

Legacy Attachments

Recent Attachments

SELECT Id, Name, BodyLength, ParentId, CreatedDate
FROM Attachment
WHERE CreatedDate = LAST_N_DAYS:90
ORDER BY CreatedDate DESC
LIMIT 200

PDF Attachments

SELECT Id, Name, BodyLength, CreatedDate
FROM Attachment
WHERE Name LIKE '%.pdf'
ORDER BY CreatedDate DESC
LIMIT 500

More Examples