How to upload files and attachments to the sobject record using REST API?
Asked Answered
A

1

5

Salesforce has two different UIs and in accordance with it, it has the possibility to store attached files differently. Two files were uploaded via the classic UI and they are marked as 'attachments'. Other files were uploaded through the new UI and they are marked as 'files'. I want to upload all of these files using REST API. I cannot find the proper documentation. Can somebody help me with this?

Autarchy answered 10/4, 2020 at 15:27 Comment(0)
J
6

That's not 100% true. In SF Classic UI you were able to upload Files too. It's "just" about knowing the right API name of the table and you'll find lots of examples online.

Attachment and Document objects have exactly same API names, you can view their definitions in SOAP API definition or in REST API explorer (there was something which you can still see in screenshot in here, seems to be down now, maybe they're moving it to another area in documentation...)

The Files (incl. "Chatter Files") are stored in ContentDocument and ContentVersion object. The name is unexpected because long time ago SF purchased another company's product and it was called "Salesforce Content". In beginning it was bit of mess, now it's better integrated into whole platform but still some things lurk like File folders can be called Libraries sometimes in documentation but actual API name is ContentWorkspace. The entity relationship diagram can help a bit: https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_erd_content.htm

ContentDocument is a header to which many places in SF link (imagine file wasting space on disk only once but being cross-linked from multiple records). It can have at least 1 version and if you need to update the document - you'd upload new version but all links in org wouldn't change, they'd still link to header.

So, how to use it?

Jemie answered 10/4, 2020 at 21:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.