Previously, on Salesforce Classic, when a file was uploaded, it was saved on the Attachment object table. This object had the Body
field.
On Lightning Experience, however, attachments are stored as Content Documents, a completely different (and arguably more complicated) set of tables.
How can I retrieve the file's body when using Lightning Experience? I mean, through SOQL.
Best Answer
The Content tables are considerably more complex than Attachments. The file content is held in the
ContentVersion
object; oneContentDocument
has one or many versions, as well as an arbitrary number ofContentDocumentLink
records connecting it to records to which it is shared.Supposing that you already have the Id of a
ContentDocument
attached to some record or another, you can get the relevant file content in SOQL:The
ContentVersion
object reference may be useful.If you need to acquire files that are attached to a specific object in Salesforce, you'd need to first perform a query against
ContentDocumentLink
and filter uponLinkedEntityId
with the Id of the record-attached-to. TheContentDocumentLink
fieldContentDocumentId
will then let you perform the above query againstContentVersion
.