I'm trying to share a record for a community user programatically. Tried below code in Execute anonymous.
// Create new sharing object for the custom object.
myObject__Share objShare = new myObject__Share();
// Set the ID of record being shared.
objShare.ParentId = 'a0Vf4000001Hprq'; //recordId;
// Set the ID of user or group being granted access.
objShare.UserOrGroupId = '005f4000000vjvX';
// Set the access level.
objShare.AccessLevel = 'Read';
insert objShare;
But unfortunately it fails with error "Line: 14, Column: 1 System.DmlException: Insert failed. First exception on row 0; first error: FIELD_INTEGRITY_EXCEPTION, field integrity exception: unknown (invalid user or group: 005f4000000vjvX): [unknown]" .
Is it not possible to grant sharing access to community users via manual sharing? I could not find a related documentation on it. Or should I set some configuration settings for this? Appreciate any help.
Thanks.
Note: This could have been achieved using Sharing sets in Community settings, but due to design constraints I'm not able to use it.