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.

2

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:

  • What is the name of the sObject for Salesforce Files? – Tyler Zika May 1 at 18:40
  • I updated in my answer. There's no single object for it, there are couple of objects associated. – Jayant Das May 1 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.

  • 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 May 1 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. – sanket kumar May 2 at 3:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.