I have the a role hierarchy like this:
manager suboridinate
profiles profiles
----------- ChildRole1.1
|
ParentRole1---------|
|
----------- ChildRole1.2
----------- ChildRole2.1
|
ParentRole2---------|---------- ChildRole2.2
|
----------- ChildRole2.3
Suppose an Individual record IndiRec1
was created by user with role ChildRole1.1
. Now this IndiRec1
needs to visible only to users with role ChildRole1.1
(also editable for all users with the record's owner role), ChildRole1.2
and ParentRole1
, because these 3 form a unit
. This visibility part I have achieved it using sharing settings and lightning component.
I have a situation where when a user with Admin
profile checks Forget This Individual
on this IndiRec1
, this record should be hidden for all profiles except for Admin
. When Admin
unchecks the Forget This Individual
it should be visible to it's original unit
.
I can think of only Apex share, which still isn't good enough:
- Make
Individual
objectPrivate
in sharing settings. - Every time an individual is created, I need to create a new individual share object,
indiShareRec
, add the recordId to the indiShareRec's ParentId. - Specify access level. For ChildRole1.2 it is
Read
and for all users with Role ChildRole1.1Edit
. - Add user or group id's. I have a public group called ParentRole1 containing ChileRole1.1 and ChileRole1.2.
- Insert this indiShareRec.
Step 3 and 4 are a problem. Because I need to give Read
access to ChildRole1.2
where as I need to give Edit
access to users with role ChildRole1.1
. How can I do this? As far as I know indiShareRec.userOrGroupId
takes a single public group id.
Any suggestions? Is it even possible?