function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Øyvind Borgersen 10Øyvind Borgersen 10 

Create/Update contentversion

Hi!

I'm trying to update some custom field on the contentversion, based on a change in another record, but it's failing. It seems like the it cannot find the contentversion to update even though I'm using I'm finding the specific recordId. 

I've also tried to create a new contentversion but get the following error: Value of class core.filemanager.FileBlobValue is not a ValueType: STRING

Anyone has a working apex or flow to update a contentversion?


 
ShivankurShivankur (Salesforce Developers) 
Hi Øyvind,

As per the documentation (https://developer.salesforce.com/docs/atlas.en-us.object_reference.meta/object_reference/sforce_api_objects_contentversion.htm), You can only update a version if it is the latest version and if it is published.

Please check with points to be considered while updating the ContentVersion Object to avoid any errors.

Hope above information helps, Please mark as Best Answer so that it can help others in the future.

Thanks.
mukesh guptamukesh gupta
Hi,

There are two ways to convert a Blob to a string in Apex. Depending on how the Blob was created, you'll use one or the other:
blobVar.toString(); 
encodingUtil.base64encode(blobVar);


For content, you should use the base64encode method. This means you'll need to create additional properties or variables in your Apex class, as you wont be able to do this on the sObject itself.

if you need any assistanse, Please let me know!!


Kindly mark my solution as the best answer if it helps you.

Thanks
Mukesh