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
Raghu Madaan 6Raghu Madaan 6 

Adding file in ContentVersion via Apex shows Duplicate Entry in Storage Usage - Content

Hello Everyone,

I am trying to create a ContentVersion Object via Apex and adding a ContentDocumentLink with CommunityId as LinkEntityId . This uploads file very well and Shows a single file in "Files" Tab. But the issue is - It is getting recorded as double the size in Storage Usage for File Storage and the "Record Count" column always makes 2 entries and incremented by 2 rather then 1 (if i upload a file using Files tab).

Same is happening with the other Scenario i tried. Created ContentVersion Object and now rather then creating ContentDocumentLink i now created ContentDistribution. Still it is recorded as double the actual file size and Record Count is increment by 2.

Now the more problem arises is : When i delete the ContentDocument Object only 1 entry is decremented in "Record Count" and File Storage space is decremented by the actual file size. And now my storage limit Exceeded as the Extra Object created by salesforce is not getting delete either and there is no option to delete it either.Emptied Recycled Bin also.
ShashankShashank (Salesforce Developers) 
Hi,

Can you please try creating manually in the UI as well and check if the issue still exists?

Thanks,
Shashank
Raghu Madaan 6Raghu Madaan 6
Hello Shashank,

I tried the same thing with UI by first creating a file and then creating a Content Delivery for it. This is not happening from the UI. From UI only one entry is coming in the storage Record UI count and file size is not saving as double the actual size.

Thanks,
Raghu
ShashankShashank (Salesforce Developers) 
Would you be able to post your code so that I can try to replicate the issue in my test environment?
Raghu Madaan 6Raghu Madaan 6
Hi Shashank,

Here you GO!!!

ContentVersion contentVersion = new ContentVersion();
contentVersion.PathOnClient = 'X_FILE_NAME.png';
contentVersion.VersionData = 'X_FILE_BLOB';//Please add any Blob data which is good in size(~500KB) so you can find the double size
contentVersion.Origin = 'H';
contentVersion.NetworkId = 'X_COMMUNITY_ID'; //You Need to Enable Communities for using this and get the communityIs from Network Object or hardcode it from from salesforce URL
insert contentVersion;

ContentDistribution contentDistribution = new ContentDistribution();
contentDistribution.ContentVersionId = contentVersion.Id;
contentDistribution.Name = 'X_FILE_NAME.png';
contentDistribution.PreferencesAllowOriginalDownload = true;
contentDistribution.PreferencesAllowPDFDownload = true;
contentDistribution.PreferencesAllowViewInBrowser = true;
contentDistribution.PreferencesLinkLatestVersion = true;
contentDistribution.PreferencesNotifyOnVisit = false;
insert contentDistribution;
ShashankShashank (Salesforce Developers) 
I tested this in the UI. Creating a content delivery (ContentDistribution) does count 2 records, 1 record which will be stored as content version file, and 1 record which is an online version for the delivery of the content.
Raghu Madaan 6Raghu Madaan 6
HI Shashank,

This really seems to be strange thing because this is not happening with me in the UI. If it is reflecting as 2 records in your UI also, does it also decrements to 2 after deleting that file.?
ShashankShashank (Salesforce Developers) 
Yes, it does. Did you try creating a content delivery from a contact record related list with a new file?
Raghu Madaan 6Raghu Madaan 6
Hi Shashank,

No actually that is not my scenario which i need. Have you tried doing it with code rather than UI..?
Kumar Saurav 10Kumar Saurav 10
Hi,

Are you looking for large file Storage in Salesforce..?
We got a solution for you…!

Here you may be interested in knowing about appexchange native app Cloud Drop which is having this feature.

For more details check:
http://www.clouddrop.io

Check Out the following URL for application:
https://appexchange.salesforce.com/listingDetail?listingId=a0N30000003IzEDEA0

Regards,
Kumar Saurav