42 votes
Accepted

Obtaining all ContentDocument records using SOQL

Just found out today that with the Spring 19' update there is a new setting in the "Setup -> Permission Sets -> (choose an existing or create a new one) -> App Permission -> Content -> Query All Files:...
  • 566
33 votes
Accepted

How to retrieve the file content for a ContentDocument object?

The Content tables are considerably more complex than Attachments. The file content is held in the ContentVersion object; one ContentDocument has one or many versions, as well as an arbitrary number ...
  • 88.2k
18 votes
Accepted

Display an image stored in ContentDocument (in lightning experience)

Looking at the Data Model of the Content Object as mentioned in this post, it looks like you need to get Id of the ContentVersion which is tied to you the ContentDocument record. Also to display ...
  • 10.1k
15 votes
Accepted

ContentDocument parentId

You need the LinkedEntityId on the ContentDocumentLink
15 votes
Accepted

How to Upload a File to a specific Library Folder using Apex?

As I can see from Your code while creating a ContentDocumentLink you are not specifying a LinkedEntityId. Linked entity ID tells in which folder it exists. So Minimum code needed to store file in a ...
14 votes
Accepted

how to upload files using Apex code

ContentDocument object does not allow insert DML operation in Salesforce, so we can upload it through the ContentVersion object, without ContentDocumentId. After DML on ContentVersion a new version ...
14 votes

Content Document download URL params

Looks like there are some changes recently. I am seeing below pattern with API version 48 For authenticated users /sfc/servlet.shepherd/document/download/06955000001UrOPAA0 For communities /...
  • 3,521
12 votes
Accepted

How to query ContentDocument and Custom object's fields at once?

You can do it in one query if you start from the Custom Object and utilize the ContentDocumentLinks relationship in a subquery. Here's an example with Account as the main object: SELECT Name, ...
  • 88.2k
11 votes

ContentDocument parentId

Yes, the documents seem to be out of date? There can be multiple entries for each ContentDocument. In the case of attachments (Lightning uses ContentDocument for attachments), there will be a record ...
  • 2,862
11 votes

Content Document download URL params

You can also download multiple files as a zip {!URLFOR('/sfc/servlet.shepherd/version/download/' & delimitedSelectedIdList &'?')} example: {!URLFOR('/sfc/servlet.shepherd/version/download/...
  • 63.8k
11 votes
Accepted

ContentDocument / ContentVersion's SharingPrivacy acceptable values

You can utilize workbench to view the details of the field. It's a picklist field with the values as below. label: Visible to Anyone With Record Access value: N label: Private on Records value: P
  • 29.4k
11 votes
Accepted

ContentVersion FileExtension

It's determined by the PathOnClient field as populated when you create the ContentVersion. As an example, in one of my orgs I uploaded a file called App.logo.png through the API, populating its file ...
  • 88.2k
9 votes

Retrieve all ContentDocument Ids whose related ContentDocumentLink record is updated/added

Triggers can fire on ContentVersion when new ContentDocuments are created or updated. See my answer to Trigger on ContentDocument not working for more on this. It appears to me, based on what I've ...
  • 40.5k
8 votes

Obtaining all ContentDocument records using SOQL

As advised by David Ha, you should add a "USING SCOPE" option in your SOQL query in order to retrieve all the ContentDocument records. Strangely, I found that "USING SCOPE Everything" restricts the ...
  • 81
8 votes
Accepted

How to query ContentDocumentLink in SOQL and then upsert records in Data Loader

This is a system restriction on ContentDocumentLink. The object reference has specifics of what you're required to do: You can't run a query without filters against ContentDocumentLink. You can't ...
  • 88.2k
7 votes

Obtaining all ContentDocument records using SOQL

If you want to delete files that are related to a single object then export ContentDocumentIds from below query and then use those ContentDocumentIds to delete files which are related to object. ...
  • 13.3k
7 votes
Accepted

How to share files uploaded in "Files" related list to Community Users

Files uploaded via this related list will only be visible to internal users, and this field is not editable. One thing you can do is post the file to the record via the Chatter publisher, and ...
7 votes

how to upload files using Apex code

I found a way to insert ContentVersion and attach it to Record in one SOQL. <apex:page controller="ContentController"> <apex:form> <apex:inputFile value="{!file}" /> ...
  • 533
7 votes

Zipping up many files (10+) for download, from a Custom Lightning Component

Great answer was found here: http://cropredysfdc.com/2016/03/16/download-multiple-contentversion-files-as-zip/ This worked for me, and I hope others find it useful. We were already using <img ...
  • 537
7 votes
Accepted

Adding attachments in apex, convert the code to add Files

Lets add two methods first, one to create a ContentVersion record: private ContentVersion createContentVersion(String name, Blob body) ContentVersion contentVersion = new ContentVersion(); ...
7 votes

How to generate a download URL for a ContentDocument in Lightning Community

The download link on the file previewer in a community generates a link of this format. It should work fine for your scenario with the exception of not being a best practice to hardcode it like this....
  • 22.4k
6 votes
Accepted

Creation order of ContentNote and ContentDocument

Disregard my ill-informed comment to your OP ContentNote is saved with key prefix 069 which is a ContentDocument. And, ContentDocument is the parent of ContentVersion (key prefix of 068). You can ...
  • 63.8k
6 votes

Obtaining all ContentDocument records using SOQL

Official response from SFDC Support is this is working as designed. There is no ability to query all content programmatically via SOQL which I suspected. You have to query ContentDocumentLink with ...
  • 2,183
6 votes

Best approach for uploading to Salesforce files via a Salesforce API

If you're using Files, you are using Salesforce Content. In fact, when you add a Chatter File, the platform is generating a ContentDocument/ContentVersion/ContentDocumentLink just as if you were using ...
  • 1,575
6 votes
Accepted

How to get ContentDocument file body blob in APEX

In query editor, you will get this. But if you do it in apex , you will actually get the blob data.Try the same query in execute anonymous
  • 573
6 votes
Accepted

Open "Content Document Preview" via Lightning Button (Lightning Web Component)

Your Apex method could return the ContentDocumentId instead, then you can benefit from the filepreview named page to have the document preview, like this: viewPdf() { this[NavigationMixin....
  • 3,595
5 votes

Obtaining all ContentDocument records using SOQL

A bit late but this worked for me SELECT ContentDocumentId,ContentDocument.Title, ContentDocument.CreatedDate,LinkedEntityId FROM ContentDocumentLink where LinkedEntityId in ( SELECT Id FROM User)
5 votes

Trigger on ContentDocument not working

Edit Your trigger definitely needs to fire on ContentVersion. I've quoted the relevant portions of the Object Reference below, having italicized two very important points under the ContentDocument ...
  • 40.5k
5 votes
Accepted

Difference between Attachments and ContentDocument

Attachments are being deprecated in favor of using Files. The ContentDocument object represents a document that has been uploaded to a library in Salesforce CRM Content or Salesforce Files. https://...
  • 22.4k
5 votes
Accepted

Retrieve contentDocument file - REST API

To get the the raw data of the document, you actually need to query ContentVersion, which is related via the ContentDocumentId. From there, you can access the VersionData field (amongst others)
  • 19.5k

Only top scored, non community-wiki answers of a minimum length are eligible