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
Rebecca MolishusRebecca Molishus 

INSUFFICIENT_ACCESS_OR_READONLY, Invalid sharing type I: [ShareType]

I'm trying to create a file (content version + contentDocumentLink) in APEX by copying data from another file. Basically, some of our files have too many versions that's eating our file storage so I'm just re-uploading the latest version of the file but want all the same sharing settings as before. This code works in my sandbox where I'm the owner of all the files, but in production I get the following error when I try to run the code through the developer console debugger:
System.DmlException: Insert failed. First exception on row 0; first error: INSUFFICIENT_ACCESS_OR_READONLY, Invalid sharing type I: [ShareType]
I'm a system administator in production, but don't own any files. I have "modify all data" and "manage CRM content" permissions. What am I missing?

In this code snippet, I'm saying for every ContentDocumentLink for the "old" file, check if there's already a CDL for that LinkedEntityID+ "new" ContentDocumentID combo. If not then create one. This insert is what's giving me the error.
User-added image
Jayeshkumar ParmarJayeshkumar Parmar

Hello Rebecca Molishus,


Make sure User has permission to the library. Please read the description of ShareType field.


Please refere below the link

https://developer.salesforce.com/docs/atlas.en-us.object_reference.meta/object_reference/sforce_api_objects_contentdocumentlink.htm

 

Please Mark It As Best Answer If It Helps
Thank You.