Hot answers tagged

30

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/...


16

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 object id here>'


14

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 objects, ContentVersion, ContentDocument and ContentDocumentLink. Below find the long answer. It turns out that the debug logs are different depending on ...


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: <...


12

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, ContentVersion> {}; Set<Id> versionsToAttach = new Set<Id> {}; contentVersions.putAll([ SELECT Id, ContentDocumentId FROM ContentVersion ...


11

You need the LinkedEntityId on the ContentDocumentLink


9

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

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....


8

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 ...


8

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 record . SELECT ContentDocumentId FROM ContentDocumentLink WHERE LinkedEntityId = '[RECORD ID]' Then SOQL on ContentDocument Select Id ,Title from ContentDocument ...


8

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 JSON or XML though, both of which are very easy to work with and can easily be converted to a CSV via an online tool or programmatically using a node, python, ...


7

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

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

This was actually solved by setting the pdf filetype to 'Execute in Browser' from Setup -> Security Controls -> File Upload and Download Security


7

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 Knowledge articles, and Site.com assets So you might need to update All records where the old user is owner so you can update related Attachment owner as well. ...


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 ...


5

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 ...


5

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


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

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 company libraries) then you can do this: Map<Id, ContentVersion> contentDocumentIdToNewestVersion; // Populate this yourself List<ContentDistribution>...


5

Try this format <apex:image url="/sfc/servlet.shepherd/version/download/[DOWNLOADID]"/>. How to get the DOWNLOADID? Open the File, you will get a screen as below. Hover on the download link, you will get the DOWNLOADID as highlighted. Replace [DOWNLOADID] with the ID of the ContentVersion record you want to display. Example: <apex:image url="/...


5

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.


5

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://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_objects_contentversion.htm


5

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 map to MIME types. ("UNKNOWN" is also one value for this field). Additionally, the original file's FileExtension is stored on these objects and could be ...


5

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. The only way I have found around it for very broad-based or global queries like the one you're interested in is a two-stage process off-platform with some ...


5

To answer to your question - Yes this needs to be a custom component. While lightning:fileUpload lets you to upload a file, to be able to view the list of the files already in the system, you need to customize the behavior as you expect by building a new lightning component. Files are stored in ContentDocument, so you will need to build a logic to retrieve ...


5

These permissions are controlled in the permission sets. To check what permission sets have this feature enabled go setup and navigate to "Permission Sets" and click on the "System Permissions" section. Once the page has loaded scroll to where it says "Create Public Links" and either tick to enable the permission or disable. Bonus tip! Using the Keyboard ...


5

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....


5

Like the option says it attaches files only when its uploaded from related list(Only from the standard related list UI). From apex you're supposed to insert a contentDocument, which is a salesforce file but what you're attaching is just an attachment. Salesforce doesn't automatically convert attachment into a file. You need to insert a file explicitly! ...


5

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 calls to RestEndpont from javascript. You can’t make Salesforce API calls from JavaScript code. For security reasons, the Lightning Component framework ...


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