2

Since we are limited to two master-detail relationships on any given record, is it possible to have more than 2 many-to-many relationships for a given object?

This seems like a rather large limitation.

EDIT: I suggest that this is a limitation as only a M-M relationship bounded by M-D lookups allow for the pass-through of information to the related list on the other object for quick reference. I realize that it is possible to create several lookups on a single object.

  • Do you mean "lookup relationship"? A many-to-many relationship involves a separate intersection object, but a lookup relationship is one-to-many, somewhat like master-detail. – Jeremy Nottingham Oct 22 '14 at 15:22
  • Can you add a link to the documentation that says "limited to two master-detail relationships on any given record"? Is this for a particular type of org? I have one object with 8 master-detail relationships. – Keith C Oct 22 '14 at 15:26
  • Under "Relationship Limits" Keith. help.salesforce.com/… – toolshed Oct 22 '14 at 15:31
  • @dphil's answer contains the key point that while an object can only have two master-detail fields, an object can be referenced by many other (>> 2) objects via their master-detail fields allowing an open ended number of many to many relationships to be created with the convenience of master-detail semantics. – Keith C Oct 22 '14 at 16:32
2

No. But the limitation of 2 Master-Details has no effect on the number of Many to Many relationships an object to have.

1) You can use lookups to accomplish the exact same thing as a Master-Detail if the only requirement is to have a Many to Many relationship.

2) The limitation of 2 Master-Details per object has no effect on the number of Many to Many relationships that use Master-Detail. In a Many to Many, the Master-Detail relationships goes on the child junction object not the parent object itself. That means all you need to do is create more junction objects (which is what makes the object many to many), with each having the maximum of two Master-Detail relationship fields.

Account <- -> Contact: Junction of AccountContactRole to create a Many to Many relationship

Account <- -> Special_Asset__c: Junction object of AccountAssetType__c to create Many to Many relationship

Account <- -> Case: Junction of AccountCaseLink__c to create a 3rd Many to many relationship.

You now have 3 junctions that all use Master-Detail to create Many to Many relationships. (Keep in mind that these are Theoretical objects I am using here and so likely make no sense in your org past my example.)

  • I realized this after the fact, it seems that I had set up my relationships improperly. What I was trying to achieve was allowing myself to pass-through information easily to related object (those on the other side of the junction). Also, the automatic deletion of children is something that I wanted to preserve. – toolshed Oct 23 '14 at 0:45
  • @Addikt Sure. Is there something in my answer that doesn't answer what you need? Also, if you are looking to delete the other side of the relationship and not just the child junction object, that can be very bad. Many to Many implies that the other side of the relationship can be in use by another similar relationship as well and so you would only want the relationship itself deleted and not the objects related to the relationship. – dphil Oct 23 '14 at 14:44
  • I was referring to cascading deletion of junction objects when using a lookup relationship. I agree that you would not wish to remove the object on the other side of the junction. I guess I can easily take care of this with APEX. Query all junctions related to a particular record and delete them. Just a pain having to code that functionality on two separate objects, and I doubt it is an efficient approach in the context of governor limits. – toolshed Oct 24 '14 at 18:24
  • Ahhh yes but my answer specifies using Master-Detail and so that manual cascading wouldn't be required. – dphil Oct 24 '14 at 19:05
0

If you use Lookup relationships instead, yes.

  • This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post. – Mohith Shrivastava Oct 22 '14 at 15:46
  • @MohithShrivastava, I disagree. I think I answered the question quite concisely. – ArtieBrosius Oct 22 '14 at 17:24
  • Can you elaborate little on this ?Any person going through this wont find it much helpful with short line answers .May be if you can elaborate we can upvote . – Mohith Shrivastava Oct 22 '14 at 17:27
  • I have small query. What is the level's of master-detail relationship(A<-B<-C<-D.....<-n).Some one please clarify. – Ramesh S Apr 11 '15 at 8:26
0

only 2 Master Details and 25 lookups we can create in an object. with apex coding you can achieve this.

  • 2
    Can you please elaborate your answer with detailed example? The line "with apex coding you can achieve this." is not very clear. – Rajiv Bhatt Apr 23 '15 at 10:59
  • only 2 Master Details and 38 lookups we can create in an object. with apex coding you can achieve this. – Vipin Indora May 24 '16 at 7:46

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.