• Rebecca Molishus
  • NEWBIE
  • 0 Points
  • Member since 2021

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 0
    Replies
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
I'm trying to move files from a user's account to a different related object's files. I know I can add a contentDocumentLink with the updated location as the LinkedEntityId to "copy" a file to the new object, but I want an independent copy that won't get deleted if the version in the original location is deleted. After a lot of research, I still haven't found an approach that works. Does anyone have a solution to this problem or is this beyond what SF currently allows you to do?