+ Start a Discussion
Pasan   EeriyagamaPasan Eeriyagama 

How to share record with a community user?

I'm trying to share a record for community user. 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]" .

User-added image

Is it not possible to grant sharing access to community users via manual sharing? I could not find a related documention 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 setttings, but due to design constraint we're not able to use it.


 
Pasan   EeriyagamaPasan Eeriyagama
Foun it in Documentation here (https://help.salesforce.com/articleView?id=users_license_types_communities.htm&type=0).

Roles and Advanced Sharing is not available for Customer Community user.

User-added image