Talk to Expert

How to Use SOQL to Filter and Bulk Download Specific Files in Salesforce?

Share this Article:

SOQL bulk file download
AI-Powered Reading

Explore This Article with AI

Get an instant summary, ask questions, or go deeper-open this page in your favourite AI tool in one click.

Thank you for reading this post, don't forget to subscribe!

A SOQL bulk file download process allows Salesforce admins to query and export specific files efficiently using ContentVersion and native export tools. A standard query would be: SELECT Id, Title, FileExtension FROM ContentVersion WHERE CreatedDate = LAST_N_DAYS:30. However, SOQL only returns metadata; it cannot “download” the binary file to your computer. In 2026, the only way to turn a SOQL result into a physical ZIP file with original filenames is using a native tool like Files Downloader.

As Salesforce Orgs grow in 2026, the “All or Nothing” approach to backups is dying. Admins no longer want to download 50GB of data just to find 10 specific PDFs.

Whether you are performing a audit, cleaning up files for Agentforce accuracy, or responding to a specific legal request, SOQL (Salesforce Object Query Language) is your best friend. But there’s a catch: SOQL finds the data, but it doesn’t “grab” the file.

Best Practices for SOQL Bulk File Download

The following SOQL bulk file download queries help admins retrieve files based on date, size, and file type. To target specific files, you need to query the ContentVersion object. Here are the three most common queries Admins use in 2026:

A. Download Files Created in the Last 30 Days

Perfect for monthly automated compliance archives.

SQL

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

B. Download Only Large Files (>5MB)

Ideal for fixing ‘File Storage Limit Exceeded’ errors.

SQL

SELECT Id, Title, ContentSize 
FROM ContentVersion 
WHERE ContentSize > 5000000 AND IsLatest = true

C. Download Specific File Types (PDFs Only)

Commonly used for extracting Case email attachments.

SQL

SELECT Id, Title, FileType 
FROM ContentVersion 
WHERE FileExtension = 'pdf' AND IsLatest = true

Why You Can’t Download via Developer Console?

If you run these queries in the Developer Console or Workbench, you will see a beautiful list of filenames and IDs. But there is no “Download All” button.

If you try to use Data Loader with these queries, you’ll hit the dreaded filename ID issue. You will get the files, but they will be named 068..., making them useless for humans. Furthermore, trying to extract thousands of files this way often triggers the Spring ’26 synchronous timeout.

The Solution: Files Downloader + SOQL

Files Downloader bridges the gap between a technical query and a physical ZIP file. It allows you to paste your custom SOQL query directly into the app interface.

 

    • Real-Time Mapping: It takes the Title from your SOQL result and applies it to the physical file.

    • Bulk Processing: It bypasses the 250MB UI download limit, allowing you to download 10GB+ batches based on your query.

Workbench Vs Data Loader Vs Files Downloader

Feature Developer Console / Workbench Data Loader Files Downloader
Filter by Date/Size Yes Yes Yes
Download Physical File No (Metadata only) Yes (Base64) Yes (Direct to ZIP)
Keep Original Names N/A No Yes
Automatic Folders No No Yes

Step-by-Step: From Query to ZIP

 

    1. Copy your Query: Use one of the templates above.

    1. Open Files Downloader: Navigate to the “SOQL Export” tab.

    1. Paste & Run: The tool will calculate the total size and number of files.

    1. Download: Hit “Process” to receive a structured ZIP file, or export the files directly to SharePoint.

Conclusion

In the era of Spring ’26 data risks, being able to surgically extract only what you need is a superpower. Don’t waste time with “All or Nothing” exports that break your browser. A scalable SOQL bulk file download strategy helps organizations export files efficiently while preserving filenames, metadata, and folder hierarchy.

Tired of looking at IDs? Start looking at Files.

Don’t let your SOQL queries stay stuck in the Developer Console. Start your Free Trial of Files Downloader and turn any SOQL result into a perfectly named, organized ZIP file today.

Table of Contents

Yes. You can filter by LinkedEntityId on the ContentDocumentLink object. However, for a surgical download, it’s often easier to use the Files Downloader List View integration.

Salesforce stores every version of a document. If you don't use the filter WHERE IsLatest = true, you will download every draft ever uploaded, which causes AI grounding inaccuracies and wastes storage. Using a clean SOQL filter ensures you only archive the final "Source of Truth."

Yes, but you must query the ContentDocumentLink object first using a WHERE LinkedEntityId IN :accountIds clause. Once you have the IDs, a bulk download tool can pull the physical files. This is the most efficient way to maintain a 4-level folder hierarchy during an export.

Absolutely. Filtering by ContentSize > 10485760 (10MB) is a primary tactic for admins fixing 'File Storage Limit Exceeded' errors. By identifying and exporting only the largest files to SharePoint, you can reclaim massive amounts of storage space in seconds.

If you try to process a large SOQL result set through the browser UI, you will likely hit the Spring ’26 synchronous timeout. To avoid this, ensure your export runs as an Asynchronous Batch Job, which allows you to process thousands of files in the background without a connection failure.

Yes. By combining a filter for FileExtension = 'pdf' with a sub-query on the EmailMessage object, you can surgically extract Case attachments for legal discovery while ignoring social media icons and signature images.