0

The Attachment object looks like the correct choice if you have a file you want to relate to only one record.

ContentDocument with ContentDocumentLink looks good if you have a single file you want to relate to multiple records.

What are the trade-offs? It appears to me that ContentDocument is the safer object to use because it does everything Attachment does, plus has more flexibility.

3 Answers 3

3

My personal opinion is go for Salesforce Files (Content objects). There are couple of good articles for using Salesforce Files over Attachment. Salesforce Files provides you more features especially when it comes to sharing when compared to the old Attachments.

There are good resources available which can help you to get more details on this topic:

2
  • What is the name of the sObject for Salesforce Files?
    – Tyler Zika
    Commented May 1, 2019 at 18:40
  • I updated in my answer. There's no single object for it, there are couple of objects associated.
    – Jayant Das
    Commented May 1, 2019 at 18:42
1

Using Salesforce files over attachments has many advantages:-

Migrating to Files instead of Attachments, or to Enhanced Notes instead of Notes, is a good idea because Salesforce Files provide you much more capabilities around sharing the file (or enhanced note) with other users, groups, or records. It also supports file previews and revisions. It is the future of managing content in Salesforce.

The sharing aspect is really important here. With classic Notes & Attachments, you must upload them to a single record and anyone who has access to that record can see the attachment.

By using Salesforce Files, you can share the file with users, groups, or records. If you needed to give someone access to the file but the user didn’t have access to the record the file was originally shared to, fine, just extend sharing of the file to the user and not compromise your org’s record sharing rules, and definitely not create more duplicates of the attachment.

The objects come to the Picture are:-

  1. ContentVersion
  2. ContentDocument
  3. ContentDocumentLink

You cannot insert ContentDocument directly. Whenever inserting ContentVersion record triggers to create ContentDocument and Contentdocumentlink in the background. You can upload multiple version of a ContentDocument using contentVersion.

ContentDocumentlink represent Represents the link between a Salesforce CRM Content document or Salesforce file and where it's shared, ContentVersion represent a specific version of a document in Salesforce CRM Content or Salesforce Files. ContentDocument represents a document that has been uploaded to a library in Salesforce CRM Content or Salesforce Files.

2
  • Is the Document object used in the process of uploading a file? You said you cannot insert a ContentDocument directly. So where do I put the blob/binary of the file?
    – Tyler Zika
    Commented May 1, 2019 at 20:05
  • @TylerZika ContentVersion object has a field called VersionData which is content or body of the note or the file, which can include properly formatted HTML or plain text. Commented May 2, 2019 at 3:58
0

ContentVersion definitely wins in the storage department for single file size, even though the documentation is a bit ambiguous about Attachment's size limit too. But there's one constraint that leaves Attachment the winner.

The maximum number of versions that can be published in a 24-hour period is 200,000. Attachments does not have this restriction, or atleast it's not documented.

Had to consider this usecase to use file storage as a log mechanism.

You must log in to answer this question.

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