41 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
  • 556
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
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, ...
user avatar
  • 86k
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 ...
user avatar
  • 86k
9 votes
Accepted

Entity 'ContentDocumentLink' is not supported for semi join inner selects

Some objects have an insanely high SOQL cost, so they're simply not allowed. For example, you also can't do semi-join selects on Task or Activity, either. The performance cost is simply too great. In ...
user avatar
  • 430k
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
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
6 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 ...
user avatar
  • 86k
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

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....
user avatar
  • 22.3k
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

ContentDocumentLink insertion fails

Using visibility to all users: link.Visibility = 'AllUsers'; You should also set the share type to this: link.ShareType = 'I'; Which means: Inferred permission. The user’s permission is ...
user avatar
  • 107
4 votes

Obtaining all ContentDocument records using SOQL

We had a similar issue with Report and it turned out the reports were under the Private space of the owners. In our case, this query gives us the full data: Select id,name,ownerid from report USING ...
user avatar
4 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 ...
user avatar
  • 10.6k
4 votes
Accepted

ContentDocumentID is not available just after ContentVersion getting inserted But available after soql query

The only value that gets updated in the Apex instance for any SObject when you insert is the Id value. Other fields populated as part of the insert by triggers or other logic have to be re-queried to ...
user avatar
  • 129k
4 votes
Accepted

ContentDocumentLink filter not working- Trailhead Conference Management App

The reason you are getting this error is because you are getting null value in recordId parameter (As mentioned by you in your comment). The solution for your problem is to make sure that you pass a ...
user avatar
  • 6,313
4 votes
Accepted

How to generate an external downloadlink for files

you can try to use this approach: public static String documentDownloadUrl() { ContentDocumentLink cdl = //You get in your own way return Url.getSalesforceBaseUrl().toExternalForm() ...
user avatar
4 votes
Accepted

ContentDocumentLink fires trigger multiple times on list insertion

Let's consider a simple ContentDocumentLink trigger and helper inspector class trigger ContentDocumentLinkTrigger on ContentDocumentLink (before insert, before update, after insert, after update) { ...
user avatar
  • 61.4k
4 votes
Accepted

INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY : [NetworkId]

I have a similar issue and this workaround helped me: Id networkId = [SELECT Id FROM Network LIMIT 1].Id; System.runAs(portalUser) { ContentVersion contentVersion = new ...
user avatar
  • 56
4 votes

Attach File (ContentDocumentLink) to Email

The key method you want to use is the Messaging.setEntityAttachments() method. This method accepts: Array of IDs of Document, ContentVersion, or Attachment items to attach to the email. See also: ...
user avatar
  • 5,459
3 votes
Accepted

Why is this ContentNote trigger receiving 1 record at a time even though multiple records are being inserted?

I created a Salesforce Case on this and that was handled promptly and effectively. Unfortunately the answer was that the current implementation supports the "one at a time" situation that arises from ...
user avatar
  • 129k
3 votes

SOQL ContentDocument: Ids not returning

I think I found a simpler solution: add the Apex user to the contentdocument.. Here is the code: //First, get all the CDLs for each object ContentDocumentLink[] cdls = [SELECT ...
user avatar
  • 1,913
3 votes

SOQL ContentDocument: Ids not returning

ContentDocument migration is really tricky. As you note in the comments, the View All Data and Modify All Data permissions do not apply to ContentDocument in the same way they do to other objects. ...
user avatar
  • 86k
3 votes
Accepted

LinkedEntityid is the user incorrectly coming in ContentDocumentLink trigger

Trigger for contentdocumentLink fired twice one for User currently uploading the document and one for the record against which document being uploaded. At the second time when the trigger is fired I ...
user avatar
3 votes
Accepted

Scheduled Data Export: how to obtain ContentVersion linking data

One thing to realize is that ContentDocument can't be directly inserted; it is inserted automatically when the first ContentVersion is inserted. ContentDocument acts as a parent for each version of ...
user avatar
  • 61.4k
3 votes

Why SingleEmailMessage.setFileAttachments() does not create visible attachments in the Activity Tab in Lightning Experience

The trick is to insert a ContentVersion first and then use the Messaging.SingleEmailMessage.setEntityAttachments method with the ContentVersion Id. The attachment goes out with the email and is ...
user avatar
3 votes
Accepted

content version - clone from one object to another

You're populating the ContentURL field, which makes the ContentVersion a Link type: [ContentURL]: URL for links. This is only set for links. One of the fields that determines the FileType It doesn'...
user avatar
  • 86k
3 votes

Community user cannot download file

Your download link doesn't work, because your user doesn't have access to file or your link is not correct. 1) To build correct link use this code: String fileDownloadUrl = URL.getSalesforceBaseUrl(...
user avatar
3 votes
Accepted

Weird Behaviour of Bulk ContentDocumentLinkTrigger in Test Context

I think the document that you have linked in the beginning of the question (bulkified) is incorrect. From what I just observed, the execution of the triggers is the other way around. That is, when you ...
user avatar
  • 1,510
3 votes

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

Salefsorce might add /s/ to your URL, making download link invalid. When you build your URL with: /sfc/servlet.shepherd/document/download/{id}?operationContext=S1 and hover your mouse over it on ...
user avatar

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