0

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]" .

enter image description here

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.

0

2 Answers 2

2

Found the related documentation on this.

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

enter image description here

1
  • and I managed to get the required design changes to add contact lookup on the object, and do it using Sharing sets in Community settings. Commented Nov 9, 2017 at 0:11
0

Customer community users cannot participate in advanced sharing. This can be worked around in 2 ways:
1.'with sharing' can be removed from class signature allowing updates/reads from within the class.
2.The ownerId of this record can be changed to point it to the Contact's ->UserId.
So, here objShare.OwnerID = CustomercommunityContact->UserID

7
  • Hi @Shalini, Thanks for the reply. 1st one is not recommended I believe. 2nd one I tried, and that is the one caused error. Was it successful for you? Probably I guess it's again 'Without sharing'. Commented Nov 9, 2017 at 0:09
  • I tried both options and they worked for different scenarios. What is the error you are getting on the 2nd one?
    – SF Learner
    Commented Nov 9, 2017 at 0:51
  • "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]" Commented Nov 9, 2017 at 0:54
  • Can you paste the code as well.
    – SF Learner
    Commented Nov 9, 2017 at 1:43
  • If you could please read my question again once more, the code and this error is mentioned there. Commented Nov 9, 2017 at 2:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .