Skip to main content
The 2024 Developer Survey results are live! See the results
20 votes
Accepted

Relationship between ContentVersion object and Document object

Content Document: It Represents a document that has been uploaded to a library in Salesforce CRM Content or Salesforce Files. The maximum number of documents that can be published is 30,000,000. This ...
Sam's user avatar
  • 258
17 votes

Content Document download URL params

You can also download multiple files as a zip {!URLFOR('/sfc/servlet.shepherd/version/download/' & delimitedSelectedIdList &'?')} example: {!URLFOR('/sfc/servlet.shepherd/version/download/...
cropredy's user avatar
  • 72.2k
17 votes

Content Document download URL params

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 /...
Victor's user avatar
  • 3,591
16 votes
Accepted

ContentDocument parentId

You need the LinkedEntityId on the ContentDocumentLink
Fernando Gavinho's user avatar
13 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, ...
David Reed's user avatar
  • 93.2k
13 votes
Accepted

ContentDocument / ContentVersion's SharingPrivacy acceptable values

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
Jayant Das's user avatar
  • 30.6k
13 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 ...
David Reed's user avatar
  • 93.2k
11 votes

ContentDocument parentId

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 ...
dacology's user avatar
  • 2,992
10 votes
Accepted

Open PDF in browser instead of Downloading

This was actually solved by setting the pdf filetype to 'Execute in Browser' from Setup -> Security -> File Upload and Download Security
G Takei's user avatar
  • 193
10 votes

Issue Setting ContentVersion Owner

Add this line: newContentVersion.firstPublishLocationId= user.Id; A more detailed explanation: When documents are created via apex (contentversion object), you need to specify the library otherwise ...
oozkan's user avatar
  • 591
9 votes
Accepted

ContentVersion Content-Type

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 ...
David Reed's user avatar
  • 93.2k
9 votes
Accepted

How can I set the ContentVersion.FileType when creating new File via Apex?

OK, I got this to work. The key to getting the FileType set correctly and thus a preview generated is to ensure that the proper file extension is set via ContentVersion.PathOnClient. Additionally, ...
Thomas Taylor's user avatar
8 votes

Best approach for uploading to Salesforce files via a Salesforce API

If you're using Files, you are using Salesforce Content. In fact, when you add a Chatter File, the platform is generating a ContentDocument/ContentVersion/ContentDocumentLink just as if you were using ...
Jeff Kranz's user avatar
  • 2,027
7 votes
Accepted

How can I insert a ContentVersion record in a test class?

public ID setupContent(){ RecordType ContentRT = [select Id FROM RecordType WHERE Name='Sales Documents']; ContentVersion testContentInsert =newContentVersion(); testContentInsert.ContentURL='<...
Tushar Sharma's user avatar
7 votes
Accepted

How to get ContentDocument file body blob in APEX

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
Preya's user avatar
  • 583
6 votes
Accepted

Body not a variable of ContentVersion?

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://...
Ryan Rudd's user avatar
  • 139
6 votes
Accepted

Upload file and attach it to contentDocument

Whenever you insert a ContentVersion, Automatically a version get inserted for the file.The number increments with each version of the document, for example, 1, 2, 3. Use ContentVersion object to ...
sanket kumar's user avatar
  • 15.4k
6 votes
Accepted

How to make ContentVersion public using Apex

Just create an instance of ContentDistribution by providing you ContentVersion and a Name and then query the DistributionPublicUrl. ContentDistribution cdl = new ContentDistribution(); cdl....
Pranay Jaiswal's user avatar
6 votes
Accepted

Field not writable: ContentVersion.FileType

FileType isn't writeable, but PathOnClient is - it's createable, but not updateable. The system will infer the type of file from the pathname extension you supply in that field. (ContentNote records ...
David Reed's user avatar
  • 93.2k
6 votes
Accepted

Open "Content Document Preview" via Lightning Button (Lightning Web Component)

Your Apex method could return the ContentDocumentId instead, then you can benefit from the filepreview named page to have the document preview, like this: viewPdf() { this[NavigationMixin....
Shamina's user avatar
  • 4,295
5 votes
Accepted

I want to associate File With Custom Object but getting Error

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 ...
Itai Shmida's user avatar
  • 5,045
5 votes
Accepted

How to convert ContentVersion VersionData to String

@Robs, You can convert the blob value of ContentVersion to string as below:- ContentVersion cv=[select id,ContentDocumentId,versiondata from Contentversion where ContentDocumentId='0697E000000HW12' ];...
sanket kumar's user avatar
  • 15.4k
5 votes

"No preview available" after uploading ContentVersion with Lightning

Start by querying in the developerConsole using something like the following: SELECT id, ContentDocumentId, FileExtension, FileType FROM ContentVersion... If the contentVersions you are uploading ...
Cleverlemming's user avatar
5 votes
Accepted

Merging Docx files into one - Apex

Aside from plain text files (e.g. source code or README.TXT type files), most files follow an internal structure. This means that two similar files (e.g. two GIF or DOCX) being "added together&...
sfdcfox's user avatar
  • 497k
4 votes

Size limit on ContentVersion object in Salesforce

From Base Lightning Components Considerations: When working with type="file", you must provide your own server-side logic for uploading files to Salesforce. [...] Uploading files using this ...
Daniel Ballinger's user avatar
4 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 ...
cropredy's user avatar
  • 72.2k
4 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 ...
ZAR's user avatar
  • 2,043
4 votes

Issue Setting ContentVersion Owner

I found from document : FirstPublishLocationId is id of the location where the version was first published. If the version is first published into a user's personal library or My Files, the field ...
Prasenjit Barua's user avatar
4 votes
Accepted

Upload large ContentVersion records

Well, I solved this. Sort of. My solution was to forgo the use of a @RemoteAction and instead use Salesforce's REST services. For those following at home home, there are two ways to do this: 1. The ...
AvailableName's user avatar
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 ...
Keith C's user avatar
  • 137k

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