39

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: Allows View All Data users to SOQL query all files in the org". This is not enabled by default for the admin user but you can at least enable it in a Profile/...


29

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 of ContentDocumentLink records connecting it to records to which it is shared. Supposing that you already have the Id of a ContentDocument attached to some ...


17

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 Contents, the relative url path should be in below format : /sfc/servlet.shepherd/version/download/contentversionid Sample code myApp.app: <aura:application ...


14

You need the LinkedEntityId on the ContentDocumentLink


13

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 of ContentDocument will be created for us in salesforce. The easiest way to do this is using inputFile and assign it to ContentVersion instance. Like this: <...


13

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 LibraryFolder named as "MyLibraryFolder" ContentVersion cv = new ContentVersion(); cv.VersionData = Blob.valueOf('Pika'); cv.Title = 'filename'; cv....


11

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 /sfsites/c/sfc/servlet.shepherd/document/download/06955000001UrOPAA0 ID in the URL being content document ID.


11

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, (SELECT ContentDocumentId, ContentDocument.Title, ContentDocument.ContentSize FROM ContentDocumentLinks) FROM Account Note that the relationship is ...


11

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 name in the PathOnClient field and App.logo in the Title field. The system inferred png as the value for FileExtension.


10

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 in the ContentDocumentLink for both the UserId and the record that is the Attachments Parent. You can use a query similar to the below to find details of the ...


10

You can directly download using the ContentVersion Id: /sfc/servlet.shepherd/version/download/<CONTENT VERSION ID starting with 068> The ContentVersion is related to the ContentDocument via a dedicated ContentDocumentId. Get the ID of the one where IsLatest is true.


10

You can also download multiple files as a zip {!URLFOR('/sfc/servlet.shepherd/version/download/' & delimitedSelectedIdList &'?')} example: {!URLFOR('/sfc/servlet.shepherd/version/download/068xxxxxxxxxxxxxxx/068yyyyyyyyyyyyyyy?')} more details on my blog


9

Triggers can fire on ContentVersion when new ContentDocuments are created or updated. See my answer to Trigger on ContentDocument not working for more on this. It appears to me, based on what I've italicized below, that you need to be querying by getting the ContentDocumentId from the ContentVersion Object instead of the ContentDocument Object, especially ...


9

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


8

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 data to Owned files only, while "USING SCOPE Team" gives all ContentDocument regardless of Owner and sharing. So this query did the trick for me (on API version >...


7

You are correct. You will have to rely on existing metadata to complete your tests. You can still create documents and put them existing library's. One thing I did in my tests for a similar implementation is to ensure that after every SQL I check to see if the list was empty. If it was I set a variable to a useful error message. Then I system.assertEquals('...


7

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. SELECT ContentDocumentId,ContentDocument.CreatedDate,LinkedEntityId FROM ContentDocumentLink where LinkedEntityId in ( SELECT Id FROM User) You can replace ...


7

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 specify the visibility in your post. This would give the attached file the same visibility as the post. Another option is to write a trigger and edit the Visibility ...


7

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 src="{!'/sfc/servlet.shepherd/version/download/'+ id}" /> for individual fine downloads. All that need to be done to make it a zip of multiple documents is to ...


7

Lets add two methods first, one to create a ContentVersion record: private ContentVersion createContentVersion(String name, Blob body) ContentVersion contentVersion = new ContentVersion(); contentVersion.ContentLocation = 'S'; // S = Stored in Salesforce contentVersion.PathOnClient = name; contentVersion.Title = name; contentVersion....


6

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 think of the ContentDocument as the header and ContentVersion as the actual "note" -- with multiple versions supported. As you edit the Note and click Save, a ...


6

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}" /> <apex:commandbutton action="{!upload}" value="Upload" /> </apex:form> </apex:page> Class: public class ContentController { ...


6

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 Filters and somehow build filter critieria across all objects in your org. =======================CASE INFO===================== However, this is how this ...


6

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


6

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 filter on ContentDocument fields if you're filtering by ContentDocumentId. You can only filter on ContentDocument fields if you're filtering by LinkedEntityId. You ...


6

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. /sfc/servlet.shepherd/document/download/{id}?operationContext=S1


5

Edit Your trigger definitely needs to fire on ContentVersion. I've quoted the relevant portions of the Object Reference below, having italicized two very important points under the ContentDocument section. You'll see that the Object Reference clearly states that the ContentVersion object is what should be used to both create and update ContentDocuments. As ...


5

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

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)


5

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]; ContentDocumentLink[] l = [SELECT Id FROM ContentDocumentLink WHERE ContentDocumentId = :d.Id]; System.debug(l.size()); System.assert(l.size() > 0); delete d; l = [SELECT Id ...


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