How to Download All Attachments from Salesforce (Classic Attachment Object)

Ask a Salesforce admin how many files the org holds and you will usually get the number shown on the Files tab. That number leaves out every classic Attachment, which in an older org can be most of the stored documents: years of contracts, emails, signed forms and case evidence uploaded before Lightning. They live in a different object, they need different queries, and export tools that only understand modern Files pass over them without an error.

This guide is specifically about the classic Attachment object. If you need Files, Notes and everything else as well, start with exporting all files, attachments and notes and come back here for the attachment detail.

What a Classic Attachment Is

An Attachment is one record with one parent. The fields that matter for an export:

FieldMeaning
IdAlways starts with 00P
ParentIdThe single record the attachment belongs to. Can be almost any object, including custom objects, Tasks, Events and EmailMessage.
NameThe file name, including extension
BodyThe binary content. Not returned by a normal query. Fetched separately per record.
BodyLengthSize in bytes
ContentTypeMIME type, such as application/pdf
IsPrivateIf true, visible only to the owner and users with Modify All Data

Compare that with a Salesforce File, which is spread across three objects and can be shared with many records. The Salesforce Files data structure article walks through that model. For the purpose of an export, the consequence is simple: Attachments and Files are two separate jobs.

Step 1: Find Out How Many You Have

Run these in the Developer Console Query Editor or any SOQL tool.

-- Total attachments
SELECT COUNT() FROM Attachment

-- Attachments by parent object type
SELECT Parent.Type, COUNT(Id) total
FROM Attachment
GROUP BY Parent.Type
ORDER BY COUNT(Id) DESC

The second query is the useful one. It tells you which objects hold the attachments and, more often than not, surfaces a parent nobody expected. EmailMessage is the usual surprise, followed by Task and a custom object from a project that ended years ago.

For total size, check Setup → Storage Usage, which lists Attachments as its own line under file storage. An aggregate SUM(BodyLength) query also works on smaller orgs but can time out on large ones.

Step 2: Understand Why the Obvious Methods Fall Short

  • The UI. You can open a record, open the Notes & Attachments list and download one attachment at a time. That is fine for ten. It is not a plan for forty thousand.
  • Data Loader. Exports the Attachment rows without the Body content. You get a list of what you could not download.
  • Data Export Service. Does include attachments if you tick the option. It runs weekly at most, delivers ZIP parts of about 512 MB with links that last 48 hours, and names each file by its record ID with no extension and no folder. Rebuilding names and parents from the CSV is on you. See Salesforce data export limits.
  • A script. Works. Each attachment body is a separate REST call to /services/data/vXX.0/sobjects/Attachment/{Id}/Body, so you also need paging, retries, API limit handling, duplicate file name handling and logging. Budget days, not hours.

Step 3: Export Them with SFDC File Exporter

SFDC File Exporter treats Attachments as a first-class export type alongside Files.

  1. Install and connect. Install the app on Windows, macOS or Linux and log in to production or a sandbox. Nothing is installed in the org.
  2. Choose the scope. Use Export from Object and pick a parent object from your Step 1 results, or Export from List View to limit it to the records in a view.
  3. Select Attachments as the file type. The same screen offers Files (ContentDocument). Run Attachments first, then Files, into separate output folders so the counts stay easy to compare.
  4. Add filters if needed. A date range or SOQL condition splits a very large object into batches that fit inside your daily API allocation.
  5. Pick an output folder and run. Attachments are written under their parent record, with their original file names and extensions.
  6. Repeat per parent object. Work down the list from Step 1 until every parent type is covered, including EmailMessage.
Tip: if you already have a list of parent record IDs from a report or Data Loader extract, use Export from CSV to fetch attachments for exactly those records.

Step 4: Prove Nothing Was Missed

An attachment export is complete when the numbers agree, not when the progress bar finishes.

  1. Compare the exported count per parent object with the GROUP BY Parent.Type result from Step 1.
  2. Check the job history for failures and re-run those.
  3. Account for private attachments. Records with IsPrivate = true are only returned to their owner or to a user with Modify All Data. If the exporting user lacks that permission, the count will be short by exactly the number of private attachments.
  4. Open a sample from each parent type and confirm the files open.
Empty files are usually a source problem. An attachment with BodyLength = 0 has no content in Salesforce either. Query for them before the export so they do not look like export failures afterwards: SELECT Id, Name, ParentId FROM Attachment WHERE BodyLength = 0.

When Teams Need This

  • Attachment-to-Files migration. Take a verified copy before converting classic Attachments to Salesforce Files.
  • Storage reduction. Old attachments are often the largest block of file storage. Export, verify, then delete. See moving Salesforce files to external storage.
  • Org migration or sunset. Attachments do not come across with a record migration.
  • Legal and audit requests. "All documents on these accounts between two dates" includes attachments on the accounts' cases, emails and tasks.

Frequently Asked Questions

How do I download all attachments from Salesforce at once?

Salesforce has no button for this. The options are the weekly Data Export Service with the attachments option ticked, a custom script that calls the REST API once per attachment, or a dedicated tool. SFDC File Exporter downloads every Attachment record as a real file and places it in a folder for its parent record, so you can run it on demand and see which record each file came from.

What is the difference between Attachments and Files in Salesforce?

They are different objects. A classic Attachment is a single record that belongs to exactly one parent through its ParentId field and stores its content in the Body field. A Salesforce File is a ContentDocument with one or more ContentVersion records, linked to any number of records through ContentDocumentLink. An export that only queries ContentDocument does not include classic Attachments.

Can I export attachments with Data Loader?

You can export the Attachment object's fields, such as Name, ParentId and BodyLength, but not the files themselves. Data Loader does not download binary content, and Salesforce's documentation says attachment export is not supported in Data Loader.

Where are email attachments stored in Salesforce?

It depends on how the email arrived and when. Attachments on Email-to-Case messages have historically been stored as Attachment records whose ParentId is the EmailMessage, not the Case, and newer configurations store them as Salesforce Files. An export scoped only to Case records misses the ones parented to EmailMessage, so include EmailMessage as a parent object.

Does my org still have classic Attachments if we use Lightning?

Very likely, if the org was created before 2018. Since Winter '18, files uploaded through the Notes & Attachments related list in Lightning are saved as Salesforce Files, but nothing converted the existing Attachment records. They stay as Attachments until someone migrates or deletes them. Run SELECT COUNT() FROM Attachment to find out.

Count, Export, Reconcile

Classic Attachments are easy to overlook because the modern interface no longer creates them. They are still in the org, still consuming storage, and still part of any honest answer to "export everything". Count them by parent type, export each type with its record context, and reconcile the totals. SFDC File Exporter handles the middle step and gives you the job history for the last.

Download Every Salesforce Attachment

Bulk export classic Attachments organised by parent record, with a job history you can reconcile against your org. Free for 50 files per export.