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
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 ...
13 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 ...
  • 456k
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, ...
  • 89.5k
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 ...
  • 89.5k
8 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 ...
  • 89.5k
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
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

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....
  • 22.6k
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
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

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 ...
  • 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 ...
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 ...
  • 10.8k
4 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 ...
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 ...
  • 132k
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 ...
  • 6,456
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() ...
4 votes
Accepted

Unable to delete ContentDocumentLink

As you can see above, when you upload a file to any record like account New Test Account, it will always create 2 links - 1st for the user TestUser with share type I (which cannot be deleted) and 2nd ...
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) { ...
  • 65.7k
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 ...
  • 56
4 votes
Accepted

ContentDocumentLink query returns different results based on LinkedEntityId size

Worked with support. It required them to enable an internal permission to overcome the issue which seems to be a limitation of 2,000 records to filter the LinkedEntityId by before you start seeing ...
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: ...
  • 5,847
4 votes
Accepted

LinkedEntityId referring to custom object record id

Yes, you can relate documents to custom objects. Here's the code I used to determine that: for(sobjecttype relatedTo: ContentDocumentLink.LinkedEntityId.getDescribe().getReferenceTo()) { if(...
  • 456k
4 votes

LinkedEntityId referring to custom object record id

The documentation does mention (though a little off-handedly) that custom objects can be set for LinkedEntityId, emphasis mine. Description ID of the linked object. Can include Chatter users, groups, ...
  • 53.4k
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 ...
  • 132k
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 ...
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 ...
  • 65.7k
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 ...
  • 1,953
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. ...
  • 89.5k

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