48 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:...
Denis S.'s user avatar
  • 626
34 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 ...
David Reed's user avatar
  • 91.7k
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 ...
Praveen's user avatar
  • 10.1k
17 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 /...
Victor's user avatar
  • 3,581
16 votes
Accepted

ContentDocument parentId

You need the LinkedEntityId on the ContentDocumentLink
Fernando Gavinho's user avatar
15 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/...
cropredy's user avatar
  • 69.1k
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 ...
Pranay Jaiswal's user avatar
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 ...
Jai Chaturvedi's user avatar
13 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, ...
David Reed's user avatar
  • 91.7k
12 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 ...
David Reed's user avatar
  • 91.7k
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 ...
dacology's user avatar
  • 2,952
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
Jayant Das's user avatar
  • 30.2k
10 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(); ...
Koen Wesselman's user avatar
9 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}" /> ...
Kritik's user avatar
  • 266
9 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 ...
David Reed's user avatar
  • 91.7k
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 ...
Sylvain's user avatar
  • 81
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. ...
sfdc's user avatar
  • 13.6k
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 ...
citizen conn's user avatar
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 ...
ATA1k's user avatar
  • 547
7 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 ...
Jeff Kranz's user avatar
  • 1,878
7 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
Preya's user avatar
  • 583
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....
Mark Pond's user avatar
  • 22.8k
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 ...
cropredy's user avatar
  • 69.1k
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 ...
CoryCowgill's user avatar
  • 2,193
6 votes
Accepted

How to prevent duplicate File (ContentDocument) if the same file is uploaded at multiple records?

Well, Apex does have that lovely heap limit of only a few MB so you can't compare the entire content of two large files. But the ContentVersion object does have a Checksum field. So in principle you ...
Charles T's user avatar
  • 10.9k
6 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://...
Mark Pond's user avatar
  • 22.8k
6 votes

Does deleting a ContentDocument delete attached ContentDocumentLinks?

Yes, deleting a ContentDocument will also delete any related ContentDocumentLink entities. I tested this out in my org: ContentDocument d = [SELECT Id FROM ContentDocument LIMIT 1]; ...
sfdcfox's user avatar
  • 477k
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....
Shamina's user avatar
  • 4,135
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)
Nicolas Evans's user avatar
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)
glls's user avatar
  • 20k

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