How can I share the Content Document Link using " Set By Record"?
I want to use the "Set by Record" sharing option of Chatter files introduced in Winter '16. As far as I understand, I have to add an AfterInsert trigger on ContentDocumentLink and reset the ShareType. But to which value? Where are they officially documented?
To share the content document link using Set By Record -
ShareType = "I", where it means:
Inferred permission. The user’s permission is determined by the related record. For shares with a library, this is defined by the permissions the user has in that library.
Other Share Types are:
V Viewer permission. The user can explicitly view but not edit the shared file. C Collaborator permission. The user can explicitly view and edit the shared file.
Given a small piece of code for this assignment
//create an account
Account acct = new Account(Name='TEST_ACCT');
insert acct;
ContentVersion contentVersion = new ContentVersion(
Title = 'Test',
PathOnClient = 'test.jpg',
VersionData = Blob.valueOf('Test Content'),
IsMajorVersion = true
);
insert contentVersion;
List documents = [SELECT Id, Title, LatestPublishedVersionId FROM ContentDocument];
//create ContentDocumentLink record for that account
ContentDocumentLink cdl = New ContentDocumentLink(
LinkedEntityId = acct.id, ContentDocumentId = documents[0].Id, shareType = 'I');
insert cdl;
Also, created a file with Set By Record at my org.
Workbench query