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
Robert Taylor 81Robert Taylor 81 

Why does ContentVersion fail to deserialize with VersionData?

Why does the following fail to deserialize?
Blob b = Blob.valueOf('test1');
ContentVersion cv = new ContentVersion(VersionData=b);
String cvString = JSON.serialize(cv);
System.debug('ContentVersion serialized: ' + cvString);
ContentVersion cvd = (ContentVersion)JSON.deserialize(cvString, ContentVersion.class);

Output
15:15:38.4 (5368573)|USER_DEBUG|[248]|DEBUG|ContentVersion serialized: {"attributes":{"type":"ContentVersion"},"VersionData":{"asByteArray":"dGVzdDE=","inputStream":{},"length":5,"maxToKeep":6}}
15:15:38.4 (10114668)|FATAL_ERROR|System.JSONException: Cannot deserialize instance of base64 from START_OBJECT value { or request may be missing a required field at [line:1, column:40]

 

AnkaiahAnkaiah (Salesforce Developers) 
Hi Robert,

Refer the below link have fix for the similar kind of issue.
https://github.com/mattaddy/SObjectFabricator/issues/16

If this helps, Please mark it as best answer.

Thanks!!
denis banksdenis banks
Content Version Object is a child of Document Object in Salesforce that represents a specific version of a document in Salesforce CRM Content or Salesforce Files. This means that this object stores document information similar to an attachment.27-Aug-2021

https://www.myadvocateaurora.net/