I want to share all records with admin user using next trigger:
trigger ContentVersionTrigger on ContentVersion (after insert) {
system.debug('sdfsdf' + Trigger.new);
for (ContentVersion item : Trigger.new) {
ContentDocumentLink link = new ContentDocumentLink();
link.LinkedEntityId = Id.valueOf('005E0000007Sew5IAC');
link.ContentDocumentId = item.ContentDocumentId;
link.ShareType = 'V';
link.Visibility = 'AllUsers';
insert link;
}
}
It throws next exception:
Insert failed. First exception on row 0; first error: INSUFFICIENT_ACCESS_OR_READONLY, Invalid sharing type V: [ShareType]
Who knows how to fix it?
Update:
If I use 'I' instead of 'V' I have another error:
Insert failed. First exception on row 0; first error:
FIELD_INTEGRITY_EXCEPTION, Document with ID: 0690L000003rtLV is
already linked with the entity with ID: 005E0000007Sew5: Linked Entity
ID: [LinkedEntityId]
But it's not true, such record doesn't exist
Best Answer
Using visibility to all users:
You should also set the share type to this:
Which means:
You can find more info here