1

If I have a scenario where there is a parent object and say 5 child objects, all linked via a master-detail relationship is there a way to use Apex sharing to add additional sharing to a child object when a record is saved, therefore adding to the master-detail sharing already defined? I realise I can't manually change sharing to child records but I believe Apex would allow that?

I want to be able to create the sharing using a user lookup field and Apex looks the only possibility. I want to give additional read or edit access to a child object but if possible still let Salesforce do the heavy lifting with the master-detail inbuilt functionality.

The main goal is to allow a core team access to everything using Profile/Permission sets. Then allow each member read access to their own records (not owned by them but assigned to them using a user lookup field) and in the same way give their manager access to read their own + their team records. 1 of the child records will be created by the team member so they will have create access to that via object security.

Is Apex Sharing the way to go to achieve this level of flexibility?

1 Answer 1

2

No. When you create a master-detail relationship, the share table and sharing-related features, like the "OwnerId" field, are completely disabled. The sharing table itself is redirected to the parent or grandparent object(s) to determine access. Attempting to write code that uses such a table will result in a compilation error: "Entity is not org-accessible." This is different than trying to reference a non-existent data type, which would show an error "Invalid Type."

3
  • 1
    So the only way to do this is dump the master-detail, change to lookup-relationship instead then manage all the security using Apex Sharing? Commented Jun 8, 2016 at 15:37
  • 1
    @chriscwharris Yes. By using M/D, you gain roll-up summaries and cascade soft deletes, but lose sharing and ownership.
    – sfdcfox
    Commented Jun 8, 2016 at 15:39
  • 1
    NB dlrs can recreate rollups declaratively so you don't strictly lose them by using lookup instead.
    – Adrian Larson
    Commented Jun 8, 2016 at 16:02

You must log in to answer this question.

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