All Questions
Tagged with contentversion apex
136 questions
11
votes
4
answers
14k
views
Isn't ContentVersion 'VersionData' Updateable (Amendable)?
I'm developing an file (attachments/contents) upload app and the process of my upload is that I upload file in chunks to ensure I'm not hitting view state.
For first chunk
insert new attachment
...
8
votes
2
answers
779
views
Query Chatter Comment Files for a group of records
My question is similar to this one except that I need the files for a group of records, making the solution of querying ContentDocumentLink unworkable, because it requires a single Id for the where ...
7
votes
1
answer
18k
views
How can I set the ContentVersion.FileType when creating new File via Apex?
I'm working on a webservice to create new Salesforce Files. To validate the underlying methods, I manually uploaded a PNG file, which shows up in the file preview in Files.
I can retrieve the ...
7
votes
7
answers
15k
views
uploading files in contentVersion using lightning component
I am developing a lightning component to upload files in the contentVersion object. I used this site as a reference:
http://peterknolle.com/file-upload-lightning-component/
I was able to ...
6
votes
2
answers
6k
views
ContentVersion FileExtension
Does anyone know how I can change the FileExtension for a new ContentVersion in a test class?
Im currently trying to create a test class for my ContentDocumentLink Trigger, in which I have an if ...
6
votes
3
answers
1k
views
Can't pinpoint what is causing DUPLICATE_VALUE error on contentDistribution insert
I have a custom app that is used for scheduling face-to-face trainings. I'm trying to set up a class that will run daily to gather all trainings scheduled for the next two weeks, and send out ...
6
votes
2
answers
494
views
Query optimization for ContentVersion
For a project I wrote a query to get all needed ContentVersion records. But after the deployment to full sandbox we have seen the performance issues with it.
It only happens for the first time, all ...
5
votes
2
answers
13k
views
Issue Setting ContentVersion Owner
I am getting an attachment via a Salesforce email service and in the Email service apex class logic, I query the user object by the email from address and set the ContentVersion owner as the user ...
5
votes
2
answers
8k
views
Trigger on ContentDocument not working
I am trying to setup triggers on ContentDocuments. The following link says that this is possible
https://developer.salesforce.com/releases/release/Spring12/contentdocument+triggers
I am able to ...
5
votes
2
answers
6k
views
Can't we query ContentVersion to get the file posted on the Object?
We have VF page that allows a user to upload an attachment that we later convert to FeedItem. THe VF Page also allows updating the FeedItem by inserting a new ContentVersion.
The whole thing works ...
5
votes
1
answer
2k
views
Apex conventversion.VersionData chunk?
We are querying for contentversion data in apex and would like to take the first part of the file data and send chunk by chunk to another webserver.
Is there a way to only take 10,000 bytes of the ...
5
votes
0
answers
2k
views
ContentPublication Limit exceeded in Unit Test
I have Apex triggers on ContentDocument and ContentDocumentLink Sobject.
I wrote my Apex Unit Tests for those triggers and I was creating more then one Content Data record to test the Logic in Bulk.
...
4
votes
1
answer
7k
views
How to query ContentDocument and Custom object's fields at once?
We have 3 objects.
OS_Account_Document__c (Custom)
ContentDocument
ContentDocumentLink
I need to query two custom fields (Document_Type__c and Custom_Document_Description__c) from the Custom Object ...
4
votes
3
answers
28k
views
How to convert ContentVersion VersionData to String
How would I convert CSV data stored in the VersionData field of object ContentVersion into a CSV String.
According to the documentation:
ContentVersion
The field VersionData is of type base64
So ...
4
votes
2
answers
201
views
PageReference to Libaries page clearing my search
I have a Visualforce page that renders part of library content in it, but I also give them the option to type in a search which will renavigate them to the default Libraries tab with the search option ...
4
votes
1
answer
629
views
How to export contentVersion using sfdx force:data:tree:export
I am looking for a way to prepopulate my scratch org with some sample data. As part of this sample data, I need to also create few content version records(images).
But the sfdx force:data:tree:export ...
4
votes
1
answer
10k
views
How to download files, documents (attachments) in salesforce via apex?
I want to download all files associated with records (single or multiple records) of a particular object at one click, using apex.
Let's say that there is a custom object myVehicle which holds ...
4
votes
2
answers
7k
views
ContentVersion file not viewable to Guest Site User
I have Salesforce Files associated with a Contact that I'd like to pluck out the ContentVersion Id in order to display the image on a public-facing Visualforce page (via Sites):
<!-- This is ...
4
votes
1
answer
1k
views
Adding Delete button to custom list controller for ContentVersion
I've been trying to have this code done with and finished for ages, and everytime I think I'm done, the person who wanted the code always adds an extra feature he'd like added in last minute. :T
In ...
3
votes
2
answers
16k
views
ContentPublication limit exceeded
Is there a limit on the content publication ?
Is this the same as content version? The docs say "The maximum number of versions that can be published in a 24-hour period is 5,000. "
Does this ...
3
votes
2
answers
4k
views
File Attachment not working when attaching crm Content
I have a page where the user selects content (that is 5MB or lower, only 2 attachments allowed per email) to use as an attachment in an email. It all seems to work fine, the email sends and there are ...
3
votes
1
answer
3k
views
How to make ContentVersion public using Apex
I want to make a ContentVersion record publicly available using Apex.
I know I can get the DistributionPublicUrl value from the ContentDistribution object.
But I don't know how I should configure ...
3
votes
1
answer
923
views
How to find enhanced domains enabled in salesforce org via apex? [duplicate]
I am looking for ways to find out whether salesforce org is enabled with enhanced domains or not via apex.
As per this document, the content (files) domain is different in each case. And dynamically ...
3
votes
1
answer
3k
views
ContentDocumentID is not available just after ContentVersion getting inserted But available after soql query
I am inserting ContentVersion as following:-
String yourFiles = 'Lets assume this is your binary string of the files';
ContentVersion conVer = new ContentVersion();
conVer.ContentLocation = 'S'; // S ...
3
votes
2
answers
2k
views
How to get Salesforce content files base URL via Apex?
As per this salesforce help document, the content files base URL is different compare to the salesforce org domain URL.
The domain URL formats with or without enhanced domains are as follows
//with ...
3
votes
1
answer
7k
views
File is uploaded in the private library or public library
I have written a triger (before insert) on ContentVersion object and I am checking that the user is going to upload the file in private library or public library.
According to my findings which I got ...
3
votes
2
answers
5k
views
Getting the Contents of a CSV File Inside ContentVersion Object in Salesforce
How can I get the body of a file stored in ContentVersion object in salesforce? I've attempted to query its contents but seems that there is no field holding the body value.
SELECT Id,...
3
votes
1
answer
1k
views
Apex Query on ContentVersion object and get all record
Apex Query on ContentVersion object and get all records, but the record are coming on current login user owned, not all records are coming. for example i am login with administrator account and want ...
3
votes
0
answers
74
views
Why doesn't ContentVersion Query doesn't respect OFFSET when you include VersionData?
I have some code where I have to be careful about how much ContentVersion data I load into memory at any particular time to avoid blowing the heap limit.
I was planning to do an initial query on ...
3
votes
0
answers
960
views
Is it possible to download archived contentversion or contentDocument
I am having a hard time downloading a contentversion/contentdocument where contentdocument is already archived.
I am trying to download the file by hitting rest endpoint
services/data/v44.0/...
2
votes
1
answer
3k
views
Field not writable: ContentVersion.FileType
In the following test method:
static testMethod void testEmailWithAttachments() {
ContentVersion contentVersion = new ContentVersion();
contentVersion.FileType = 'Text';
...
2
votes
1
answer
437
views
Why Blob equals doesn't work if one of the Blobs is retrieved from ContentDocument?
In brief, I can't test the value stored in a ContentDocument. Even if the value of the two Blobs is the exact same, equals would return false. Do someone know the reason?
Here's a unit test to check ...
2
votes
1
answer
406
views
Add opp id field into ContentVersion Post Insert
i am trying to add the opp id for a content version to the content version once it is created
i am running into issues where the record is read only, how can i update this object when it seems to be ...
2
votes
1
answer
2k
views
What controls ContentVersion access in non-sharing apex class?
I recently wrote an apex class which queries the ContentVersion records for a lead and embeds them in a PDF page. The class is not running with Sharing, so system access, and everything is working in ...
2
votes
1
answer
1k
views
File corrupted on sending data to create file via workbench using REST API
I am trying to create a file in in salesforce via workbench. The file is getting created although the file is corrupted. I feel there is some issue in binary data. What I am doing to get the binary ...
2
votes
1
answer
924
views
File saved using ContentVersion appears distorted or low quality
Using this link - Convert event.target.files into a JSON string I was able to get the file data. I form a JSON with like - {'fileName':xyz.jpeg,'file': <fileContent>} and pass it to an Apex ...
2
votes
2
answers
2k
views
Specify ContentSize when creating new ContentVersion in UnitTest
I used the post: Test class for contentdocumentlink as a model, however, when I attempt to define my own ContentSize for the ContentVersion document I receive:
Field is not writable: ContentVersion....
2
votes
2
answers
5k
views
Copying ContentVersion Image File from one record to another with Apex
Is it possible to copy a ContentVersion image associated with one record so that the copy is associated with a different record?
Code below gives me the following Execute Anonymous error.:
Line: ...
2
votes
1
answer
4k
views
Allowing customer portal users to download attachments
I'm trying to implement a feature in out customer portal that allows the users to upload a document (which is then stored as an attachment on a custom object) and retrieve it again. I've managed to ...
2
votes
1
answer
4k
views
How to delete latest version from ContentDocument?
Is there any way we can delete Latest Version from ContentDocument?
I have tried deleting ContentVersion, but DML Operation Delete is not allowed on it.
I have tried deleting ContentDocument, but it ...
2
votes
2
answers
1k
views
BLOB is not a valid UTF-8 string for the Contentversion of einstein_platform.pem file
In Einstein Playground app developed by the Salesforce Lab, I have uploaded the einstein platform service private key file named einstein_platform.pem to complete my einstein platform service setup. ...
2
votes
1
answer
1k
views
Test Class for ContentDocumentLink causing Internal Salesforce Error
I have a test class that is inserting a ContentDocumentLink between a ContentNote (SNOTE) and a custom object. Everytime I try the insert it causes an Internal Salesforce Error. I have absolutely ...
2
votes
1
answer
386
views
In Apex, how do I know if my user can contribute content to a particular library?
Is there a way to discover if the current user can publish content to a specific Library using either Apex or Javascript?
Use Case
I have a shared library (DeveloperName = Shared_Forms) that many ...
2
votes
1
answer
1k
views
Is it possible to customize the error message that appears when the user is unable to upload a file?
I'm trying to make a trigger that prevents the user from uploading a file that is larger than 100mb. I'm doing this by checking the file size in the ContentVersion trigger and using addError.
However,...
2
votes
2
answers
1k
views
Is there any way to get or edit the metadata in images posted to salesforce?
Is there a way through apex or using the VersionData of the ContentVersion for me to change that EXIF data of a ContentVersion image so that it won't register as needing to rotate?
To be more ...
2
votes
1
answer
4k
views
Querying ContentVersion or ContentDocument for User Other Than Owner - Only One Record At a Time?
My issue is that I can't seem to query more than one record at a time from the ContentVersion or ContentDocument if I'm not the owner of the file. Here is what works for me:
Map<Id,...
2
votes
1
answer
1k
views
no preview for ContentVersion when inserting from Apex
I'm using the following code to generate ContentVersion.
String title = 'sample file.txt';
ContentVersion contentVersion = new ContentVersion(
VersionData = Blob.valueOf(...
1
vote
1
answer
3k
views
"No preview available" after uploading ContentVersion with Lightning
I get my test image in files, but can't to see the preview. How can I fix that?
@AuraEnabled
public static void save(String resumeId, String versionData){
ContentVersion ...
1
vote
1
answer
803
views
I have used Multipart/message but still i got the error as heap size limit too large. I'm able to send below 2MB file
I have used Multipart/message to send Large size of file from Salesforce to External system. but still I got the error as heap size limit too large, I'm able to send below 2MB file.
Source Org
public ...
1
vote
1
answer
5k
views
Create a ContentVersion document available for all users
Sorry if this seems easy, but I am new to Salesforce...
What I did so far is:
Query files using apex
Do operations according to VersionData of queried files
Everything works as expected. However, ...