Hot answers tagged

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


19

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


17

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

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


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

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.


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

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


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

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


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

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

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=0 There is an idea you can upvote here: https://success.salesforce.com/ideaView?id=0873A000000E3ZTQA0


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


7

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


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


7

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. I'd use a method to read the files that is asynchronous: readFile(fileSource) { return new Promise((resolve, reject) => { const fileReader = ...


6

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


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

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


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

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


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

You should add location for the file (the library), I use ContentLocation for creating my ContentVersion: ContentVersion cv = new ContentVersion(); cv.ContentLocation = 'S'; // S = within Salesforce, E = External cv.VersionData = body; cv.Title = fileName; cv.PathOnClient = filename; insert cv;


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


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