19
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 ...
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
/...
15
votes
Accepted
13
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/...
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,
...
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 ...
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 ...
11
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
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 Controls -> File Upload and Download Security
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, ...
8
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 ...
8
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 ...
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='<...
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
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://...
6
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 ...
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....
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 ...
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....
5
votes
Trigger on ContentDocument not working
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 ...
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 ...
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 ...
5
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 ...
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&...
4
votes
Accepted
Migrating Chatter files attached to feed comments
I was able to work around this by inserting new ContentVersion with the following:
OWNERID: 005o0000002DMoTXXW (my id, or believe you can omit)
TITLE: title of file
PATHONCLIENT: C:\sfdc-migration\...
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 ...
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 ...
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 ...
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 ...
4
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' ];...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
contentversion × 377contentdocument × 135
apex × 132
files × 75
contentdocumentlink × 69
content × 33
rest-api × 32
trigger × 27
soql × 26
visualforce × 24
unit-test × 23
attachment × 18
lightning-web-components × 17
blob × 14
api × 10
lightning × 9
contentnote × 9
lightning-aura-components × 8
community × 8
data-loader × 8
javascript × 7
opportunity × 7
fileupload × 7
after-trigger × 6
libraries × 6