All Questions
Tagged with contentversion apex
136 questions
1
vote
0
answers
1k
views
Inserting Content Version via Community User in test class Failing
I think this is very straight forward I just can't figure out the issue behind it.
Error:
: Insert failed. First exception on row 0; first error: INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY, You do ...
1
vote
1
answer
3k
views
Unable to insert ContentVersion record in future method in apex [duplicate]
In a partner Community, I am inserting a ContentVersion record before doing future callout and also inserting ContentVersion record within future callout .
I am able to insert ContentVersion record ...
1
vote
1
answer
751
views
No such column 'ContentDownloadUrl' on entity 'ContentDistribution'
When I am trying to query ContentDownloadUrl on the entity ContentDistribution I am getting the error as
'No such column 'ContentDownloadUrl' on entity 'ContentDistribution'.
But when I am executing ...
0
votes
0
answers
881
views
How to add a new image file into ContentVersion using Apex?
I have a URL which is a PNG file which is hosted on external cloud and I would like to create a new file with this image in my salesforce opportunity object as a file. Could anyone point me on how to ...
0
votes
1
answer
634
views
When and If, Does the 'version' in ContentVersion Change?
I'm using the lightning-file-upload component to upload files (wow).
My question is: is it safe to add a custom lookup relationship on the ContentVersion object?
I guess I don't really understand the '...
0
votes
0
answers
40
views
How to create a public Url for an attachment? [duplicate]
I used a lightning:fileUpload to insert a file into the Attachment object:
<lightning:fileUpload
recordId="{!v.patientId}"
aura:id="fuploader"
name="files&...
0
votes
1
answer
3k
views
Content Version SOQL - WIth custom field in the Where clause Return as null
I have a custom field on Content Version - but When I try to have a SOQL and receive the data its return as null.
The next line is working :
ContentVersion testContentInsert = new ContentVersion();
...
0
votes
1
answer
265
views
ContentVersion apex decoding [closed]
we are saving a docx and pdf files in contentversion. But having issue in decoding it back.
Blob.tostring doesnt work as the files encoding is not in the UTF-8 formatting.
Can you please help me ...
1
vote
3
answers
2k
views
upload a file in VF page to content Version is broken
I have a huge and complex vf page (force.com site) - So I will try to explain my issue with an example instead publish here all the code - I hope it will be understanble:
I want to upload a file from ...
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 ...
0
votes
2
answers
2k
views
Prevent files from being duplicated ContentVersion - ContentDocumentLink
I have button, when click on it, it'll generate a doc and stock it in Files
I want to > when i click on that button again, the doc will not be duplicated
Code
ContentVersion contVer = new ...
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
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 ...
0
votes
0
answers
778
views
Transfer Notes and Attachments from One Object to Another
need help figuring our my batch job that moves Notes and Attachments from one object(dsfs__DocuSign_Status__c), to its related Account, then delete the notes and attachments after they are moved. I ...
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 ...
0
votes
1
answer
2k
views
Report on Notes and Files that are shared with accounts
I have a requirement where I need to get the file names or count of files that are uploaded under each account in Salesforce. I understood that the notes and attachments can be queried from content ...
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
385
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,...
0
votes
0
answers
143
views
Email notification on ContentVersion object
I am sending an email notification if a field is changed on Content Version object through Apex as we cannot create Workflows/processbuilder on Contentversion object. In my Apex code, I am referring ...
0
votes
2
answers
833
views
Unable to access versionData from test class
I am facing an issue but I don't know what I'm doing wrong.
I'm writing a test class for a code which has this 2 lines:
public static Blob getPkpass(){
// more code here...
List<...
0
votes
1
answer
2k
views
unrecognized base64 character apex
I converted a pdf file in base64 with javascript.
function convertToBase64() {
//Read File
var selectedFile = document.getElementById("inputFile").files;
var cvfiles = document....
0
votes
1
answer
296
views
Linking ContentDocuments to Products
I am looking to associate ContentDocuments to Product2 records based on values in the ContentVersion record. For example I am uploading a new File record in Salesforce that is a document about ...
0
votes
0
answers
187
views
Error while inserting a new revision of a file programatically
I am trying to upload a new revision of a file in ContentVersion object programmatically by Apex. I am getting the below error while inserting a new record of ContentVersion.
15:21:52:424 ...
1
vote
1
answer
1k
views
Stuck writing a test class for ContentDocumentLink object apex trigger
I am trying to write a test class so that I can send the following trigger live in our production system:
trigger updateDocTitleFileExt on ContentDocumentLink (after insert) {
for (...
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';
...
1
vote
1
answer
946
views
How to create a new contentversion(pdf) using the existing contentversion(word) version data
I want to generate the pdf file using word document. I was trying to create the new contentversion(pdf) using the existing contentversion(word) versiondata. However, the pdf is not opening after ...
0
votes
1
answer
5k
views
ContentVersion - Problem with base64 encoding when creating the record
I am writing a WS which gets a request base64 String & other parameters which should be used to create ContentVersion record.
I tried the following from dev console.
When I user base64Encode ...
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 ...
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/...
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
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 ...
1
vote
1
answer
2k
views
How to upload multiple files to ContentDocumentLink Object in one call from a lightning component?
I want to upload multiple files from a public site to salesforce ContentDocumentLink. How I can create bulk of files on javascript (client) side and handle them from apex?
Lightning Component:
...
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 ...
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 ...
1
vote
0
answers
622
views
INVALID STATUS on ContentVersion create from Attachment [duplicate]
I'm currently trying to create ContentVersion records from Attachment ones but it's giving me the following error:
INVALID_STATUS, Documents in a user's private library must always be owned by that ...
0
votes
1
answer
2k
views
Cannot able to get ParentId from ContentDocument
I have a below code to retrieve parentId of content document after insert on ContentVersion.
//get blob body content from ContentVersion
for(ContentVersion cVersion : [SELECT Id, versionData,...
0
votes
1
answer
2k
views
Could not able to retrieve VersionData from Content Version after insert of ContentDocument
I am trying to retrieve the body of ContentDocument after insert.
Below is my code.My trigger is on ContentDocument (After Insert)
public static void syncContentDocument(List<ContentDocument> ...
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 ...
0
votes
1
answer
99
views
Related Files Component
I have a component and apex controller that calls/displays all the related files on a record.
How can I filter the returned files by a field that is set on ContentVersion?
ie. only show files if ...
0
votes
0
answers
686
views
Insert ContentVersion without VisualForce
I've got a CSV file stored on the user's hard drive and I want to store it in Salesforce. The code I have uses Visualforce and Apex to, I think, open up the file and place the contents on a hidden ...
0
votes
2
answers
2k
views
Unable to get file attached to Account using Apex
I have a file firstname lastname cv.pdf attached to an Account record.
I would like to get the file using apex, below is my attempt:
List<ContentVersion> files = [SELECT Id, VersionData
...
0
votes
2
answers
3k
views
content version - clone from one object to another
I am trying to clone File(s) from a parent object to child. The code I am using is doing that but the file type is set to "LINK" while doing so, and I am unable to open that file or it has nothing ...
1
vote
1
answer
45
views
What kind of test can I write to check the file?
I have a controller for VF Page. This code upload a profile's image (we can see it after that) and delete it. What kind of test can help me to check this file? I need to know, is it uploaded or not.
...
0
votes
2
answers
1k
views
Make the test work: File insert, check this File
This code is a controller for my VF Page. It inserts ContentVersion and ContentDocumentLink. After that a candidate field Photo__c take a ContentVersion.Id value. How to check it correctly?
Now ...
1
vote
1
answer
4k
views
ContentVersion: how to check File Type and File Size?
I need to check Max Image Size and File Type so I can display the correct error in ApexPages.Messages. I tried to do something like this:
if (conVer.FileType != '')
But I don't know what FileType ...
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 ...
6
votes
2
answers
493
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 ...
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 ...
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(...