0

I have requirement where a custom objects needs to have multiple objects as its parents. For example a custom object must have master-detail relationships with Account, Opportunity, Case etc. We can set only two Master detail relationships on a custom object.

So I am not able to figure out any way in which we can setup this. Can anyone please suggest an approach.

I need the relationships to be M-D because we need the sharing of the object to be controlled by parent.

1

We cant create more that M-D on any object and there is really good reason why Salesforce do now allow us to create more than 2 two. Read more about data skew problem if you want to know why.

If you want to control sharing based on other(parent) record access then you can simply make all objects private and create your won sharing rules or apex manual sharing and achieve same functionality with out M-D.

1

As you have already stated, you can have at most two master-detail relationships with your custom object on the detail side. Also, only one of them is the main parent. The usual use case of two master-detail relationships is in junction objects. There is no way to have more than two master-detail relationships on an object but you can fake them with several mandatory lookup relationship. There are still some differences, it will be good to know why you need multiple parents for your object in the first place in order to make a more complete and satisfactory answer to your question.

—-

Some of the main differences include:

  • Deletion - When the parent in a master detail is deleted, all its children are deleted. Similarly, when it’s undeleted, all of them are undeleted. The first part is achievable even with lookup but since it can lead to flaws in security it is not selectable by default. The second part is not documented in lookups.
  • Ownership - The owner of the detail side object is the owner of the master side object. In lookups they can be different.
  • Security - Detail records inherit security settings and permission from master record and cannot be set independently.
  • When setting up the multiple mandatory lookup relationships, make sure you set the deletion constraint appropriately. You may also want to add triggers on the "fake parents" to ensure that the "children" get deleted when the "fake parent" is. The biggest difference after that (and ignoring sharing control) is that you cannot base rollup formulae on these "fake parents'" children. – Phil W Jun 4 '19 at 6:51
  • @PhilW There are also differences in visibility and permissions. Since I don’t know if OP really need to have multiple master-detail relationships I’ve not posted a really complete answer. – gvgramazio Jun 4 '19 at 6:53
  • Worth mentioning each of these as caveats in the answer, to my mind. I know you did say there are "some differences", but it is good to crystalize them, at least in summary. – Phil W Jun 4 '19 at 7:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.