Hot answers tagged

44 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:...
  • 586
21 votes
Accepted

Triggers on ContentObjects

Alright, I spent a couple of days going through it all, and the short answer is: it's complicated. Depending on what you want your triggers to do, you may need to have different triggers on different ...
17 votes
Accepted

How to query all files attached to the Opportunity

Solved. The file is actually a content document and could be easily obtained via foreign key: SELECT ContentDocumentId FROM ContentDocumentLink WHERE LinkedEntityId = '<Opportunity or other ...
  • 2,063
16 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,571
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 ...
13 votes

Files as email attachment from Apex

If you have the ContentDocument Id you can fetch the ContentVersion file as this: // If you only want the ContentVersion ID's Map<Id, ContentVersion> contentVersions = new Map<Id, ...
  • 1,882
13 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/...
  • 65.9k
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,882
9 votes
Accepted

Open PDF in browser instead of Downloading

This was actually solved by setting the pdf filetype to 'Execute in Browser' from Setup -> Security Controls -> File Upload and Download Security
  • 183
8 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}" /> ...
  • 542
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 a file uploaded as an attachment in lightning experience?

Files are stored in the ContentDocument Object .You will have to run a SOQL against contentDocument link first and look for all Content Version DocumentLink with EntityId as the ParentId of the ...
8 votes
Accepted

Is there a tool to run all tests and generate a coverage report?

You can use the ApexCodeCoverageAggregate object available in the Tooling API to obtain coverage information. However, this is not going to come down in an excel format. You can request this data in ...
  • 3,972
8 votes
Accepted

ContentVersion Content-Type

The ContentVersion and ContentDocument objects don't store MIME types. They do, however, store a FileType, which contains strings like "WORD_X", "PDF", and "POWER_POINT_X", which you could potentially ...
  • 89.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 ...
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.5k
7 votes
Accepted

Where are the documents from the Documents tab in Lightning?

Documents are not available in Lightning Experience. You need to switch back to Classic to access them. https://help.salesforce.com/articleView?id=lex_gaps_limitations_files_and_content.htm&type=...
  • 879
7 votes

What contributes to Salesforce File Storage?

As per Salesforce docs: File storage includes files in attachments, Files home, Salesforce CRM Content, Chatter files (including user photos), the Documents tab, the custom File field on ...
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 see anonymous code debug logs in visual studio code?

You can see the logs by Opening the Command Palette and enter sfdx get in the search box Then choose SFDX: Get Apex Debug Logs... After a few seconds, you are prompted to select a debug log to ...
  • 7,808
7 votes
Accepted

Uploading Multiple file using fileReader in lwc

Reading a file is asynchronous. This means that the upload code will happen before the files are read, and there won't be any files to read, so nothing happens. Instead, you need to wait for the files....
  • 457k
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,193
6 votes
Accepted

Body not a variable of ContentVersion?

For ContentVersion, the property that contains the blob data is 'VersionData'. Line 6 should be changed to: controller.file.VersionData = Blob.valueOf('populated'); See more here: https://...
  • 139
6 votes

Query to see all Files related to specific object (Events)

ContentDocumentLink, as you can see from that error message, has very strict requirements on how you can query it. You must supply a literal Id value or a set of Id values. This is a major limitation....
  • 89.6k
6 votes
Accepted

Is it possible to create a button to download all files attached to a record?

I don't think it would be possible easily in lightning. The sessionID in lightning is not API enabled, Thus you cannot access standard rest endpoint to download files. On top of that you cannot make ...
5 votes

How to query a file uploaded as an attachment in lightning experience?

In lightning when you upload attachments, it save as salesforce files. for querying salesforce files you need to understand three object: ContentVersion ContentDocumentLink ContentDocument for each ...
  • 14.2k
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

Migrate attachments to Salesforce Files

FYI Douglas Ayers has a package for automating this via Apex: https://douglascayers.com/2015/10/10/salesforce-convert-attachments-to-chatter-files/

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