Hot answers tagged

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:...
user avatar
  • 566
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 ...
user avatar
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 ...
user avatar
  • 2,053
15 votes
Accepted

ContentDocument parentId

You need the LinkedEntityId on the ContentDocumentLink
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 ...
user avatar
14 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 ...
user avatar
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, ...
user avatar
  • 1,862
12 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 /...
user avatar
  • 3,501
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 ...
user avatar
  • 2,862
10 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/...
user avatar
  • 63k
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
user avatar
  • 183
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 ...
user avatar
  • 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 ...
user avatar
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 ...
user avatar
  • 3,952
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 ...
user avatar
  • 87.4k
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 ...
user avatar
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}" /> ...
user avatar
  • 533
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. ...
user avatar
  • 13.3k
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=...
user avatar
  • 849
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 ...
user avatar
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(); ...
user avatar
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 ...
user avatar
  • 7,683
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....
user avatar
  • 439k
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 ...
user avatar
  • 2,183
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....
user avatar
  • 87.4k
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 ...
user avatar
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 ...
user avatar
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)
user avatar
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/
user avatar
5 votes
Accepted

Public Imageurl

You can insert a ContentDelivery, and then get the URL of that. If you have a set of ContentDistributions (and can fill in some blanks that I've removed becomes I'm relying on some of our internal ...
user avatar
  • 12.9k

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