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:...
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 ...
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 ...
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
/...
16
votes
Accepted
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/...
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 ...
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,
...
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 ...
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 ...
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
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();
...
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}" />
...
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 ...
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 ...
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.
...
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
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 ...
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 ...
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
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....
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 ...
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 ...
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 ...
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://...
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];
...
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....
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
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)
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
contentdocument × 355contentversion × 138
apex × 120
contentdocumentlink × 110
files × 67
soql × 43
trigger × 40
content × 33
attachment × 25
visualforce × 21
unit-test × 18
lightning-web-components × 14
lightning × 12
rest-api × 12
community × 11
lightning-aura-components × 10
contentnote × 10
opportunity × 7
chatter × 7
force.com-sites × 6
feeditem × 6
libraries × 6
chatter-file × 6
email × 5
visual-workflow × 5