How To Download All Attachments Of All Records Of A Custom Object In Salesforce?
I am new to file handling in Salesforce. I want to grab all the files attached to all the records of a custom object. Can anyone help me with it?
Old-school SF used
Attachment object and you could simply go
SELECT Body, ContentType, Name FROM Attachment WHERE ParentId = '...'.
In Lightning there's high chance your attachments are called "Files" (the actual API name is
ContentVersion). Check if the attachment's ID starts with 068 or 069. They aren't linked directly to your record. Instead there's
ContentDocumentLink table sitting in between, used to cross-share same file. (You upload it and waste database space once, then you can cross-link it in Chatter posts, groups, other records...)
The official ERD isn't great, try to click through it in Setup -> Schema Builder or this answer might help: https://salesforce.stackexchange.com/a/160285/799. There's a sample query which you might have to fine-tune a bit, for example to
SELECT ContentDocument.LatestPublishedVersion.VersionData to get the actual payload.
Check out other questions around here about
ContentVersion. For example https://stackoverflow.com/a/48668673/313628 (it's other way around, about upload but should give you good idea).
- → Is It Possible To Use An External Database For User Data & Login Credentials With Shopify?
- → Change Database Source Depending on Login Credentials
- → JSON iteration in JAVA using jettison library
- → SyntaxError: Cannot use import statement outside a module in JEST LWC
- → Salesforce REST API query - URL limit
- → Regex to mask characters except first two digits in Java
- → How to make Multilevel Drop down navigation in wordpress theme?
- → laravel salesforce require_once?
- → Getting "INVALID_FIELD_FOR_INSERT_UPDATE" error message when try to update Salesforce Contact objet via Java(EnterpriseWSDL)
- → Infinite loop on ComponentWillMount ReactJS
- → how to get current date in MOMENT.JS Dynamic
- → Why i can't add Approval record row into the CR ticket
- → Pagination In Custom APEX REST Endpoint