I am trying to extract notes and attachments related to a custom Salesforce Object. I have tried to use the workbench and data loader. Data loader does not work because you cannot use nested SOQL queries, and the workbench doesn't work because I cannot create a bulk load .csv file with the nested query. I cannot create a report in the UI either, as file and content reports don't seem to include the parent object details.

Basically, is there any way to export all notes and attachments associated with a specific custom object without creating custom apex or downloading a 3rd party app?

Here is my query:

select Id, Name, CreatedDate,
(SELECT Id, Name, CreatedDate FROM Attachments), 
(SELECT Id, Title, CreatedDate FROM Notes)
from CustomObject__c
  • 2
    You should be able to load them as two separate queries directly against the child tables. So try SELECT Id, Name, CreatedDate FROM Attachment.Type = 'CustomObject__c' And similarly for Note.
    – Adrian Larson
    Jul 3, 2018 at 16:37
  • 1
    But be aware that new-style Notes and Files don't attach like Attachments, so if your org is using Lightning Files anywhere, that's a third, more complex query against ContentDocument/ContentDocumentLink.
    – David Reed
    Jul 3, 2018 at 17:33
  • Thank your quick response and your help on this! However, it looks like this query isn't working either. Here is what I entered: SELECT Id, Name, CreatedDate FROM Attachment.Type = 'Entitlements__c'. From there, I received a Malformed_Query error. I am trying this in the workbench - should I be using a different tool? Thanks again! Jul 3, 2018 at 18:16
  • I think there's just a typo. Try SELECT Id FROM Attachment WHERE Parent.Type = 'Entitlements__c'
    – David Reed
    Jul 3, 2018 at 18:24
  • Success!! You're a life-saver. Thank you! Jul 3, 2018 at 18:24

3 Answers 3


I'm going to add a little more detail here.

There's a total of four kinds of note and attachment object you might be seeing on your objects, and they're queried in different ways.

Classic Attachments

SELECT Id FROM Attachment WHERE ParentId = 'SOME_ID'



will get you data on your old-style Attachments.

Classic Notes

These work just like Attachments, but with a different sObject:




Content Notes and Content Documents

Content Notes are the new-style "Enhanced Notes". They're built on the Content architecture under the hood, and have rich-text bodies.

Content Documents (with associated Content Versions) represent the new Lightning Files.

Unfortunately, both are related to records using the ContentDocumentLink object, rather than having a direct lookup, and this comes with some significant query limitations:

You can't run a query without filters against ContentDocumentLink. You can't filter on ContentDocument fields if you're filtering by ContentDocumentId. You can only filter on ContentDocument fields if you're filtering by LinkedEntityId.

You can't filter on the related object fields. For example, you can't filter on the properties of the account to which a file is linked. You can filter on the properties of the file, such as the title field.

A SOQL query must filter on one of Id, ContentDocumentId, or LinkedEntityId.

So, to be short, you can't query all ContentNote or ContentDocument records attached to some specific type of object easily.

You'd have to do something like exporting all Ids for a given sObject type and iteratively querying sets of those Ids against the ContentDocumentLink table to locate attached files. This is something I've done before (and written about here), but it takes some Python or another scripting language to get it done.

If you do have a specific Id or Ids of records whose attachments you want to find, you can do it like this:

SELECT ContentDocumentId, ContentDocument.Title FROM ContentDocumentLink WHERE LinkedEntityId = 'OBJECT_ID'

Note that Content Notes are returned in a Content Document query - they are just a special type of Document.

  • Syntax is invaluable. Thank you.
    – Rogelio
    Aug 29, 2022 at 23:45

It looks like you already found out your answer, but the way you formulated your question makes it look like you want the actual content of those attachments (like pdf files associated with an account, for example), so I'll just leave this answer anyway.

You can export the data in your organisation through the Data Export feature, which can be found on Setup > Data > Data Export. You can choose to schedule that export or choose to export now. On the same page, you can select which objects to include.

export page

So you would check both checkboxes, and select just the "Account" checkbox, for the example I proposed. The downside is that it will export everything on every account in the organisation. Fortunately, the data is organised by the record identifier, so you can easily find the documents associated with a specific account.


You can export all notes and attachments using open-source sfdx-hardis plugin command

  • First, define a files export


  • Then, run the files export

sfdx hardis:org:files:export

More details in this article

enter image description here

Disclaimer: My company authors sfdx-hardis plugin

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .