function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
vsabbellavsabbella 

Using lookup to configure many-many relationships.

Can we configure many - many relationships using lookup on junction object?  If we can, what is the difference between using master detail and lookup on junction object to create the many-many relationships.

Marko LamotMarko Lamot

Yes you can.

 

Master detail ->  parent must always exist;

Lookup ->  parent does not need to exist;

 

p.s. If you have master detail you can then user roolup summaries on master.

 

 

AshlekhAshlekh

Hi,

 

Good question.

 

Say I have two object ,Obj_A and Obj_B and  Now I want to relate this two object by many to many relationship.

For this I have two option.

1)  By creating a Third Object Obj_c and make this object as detail object of Obj_A and Obj_B.

     then Obj_c is called juction object  eg:   OBJ__A ==> OBJ__C(jucion Object)  <== OBJ__B.

     Jucntion can't be master of other object. And if a record of Obj__A or Obj_B is  deleted then record of juction object will  

     deleted automatically .And juction object always inhert the sharing property of primay master object

2) In the case of look up relationship if reocord of Obj_A or Obj__b is deleted then it's i up to you what should be happen     

    with record of obj__c . Obj__C is not a juction object. and you can create master detail relationship. 

 

Thanks 

Ashlekh

 

if you like my post then please mark as a solution and don't forget to give me kudo's 

 

sandeep@Salesforcesandeep@Salesforce

To setup a many to many relation ship Mast Detail relationship is a perfect solution.

souvik9086souvik9086

Yes we can configure the same both with lookup and master-detail.

 

Master Detail - In junction object the parent field is mandatory and junction object data will be deleted if you delete parent data.

Lookup - In junction object the parent field is  not mandatory and junction object data will not be deleted if you delete parent data. 

 

If this post is helpful please throw Kudos.If this post solves your problem kindly mark it as solution.

Thanks

Mukesh Kumar 107Mukesh Kumar 107
Though you can use Lookup Relationship for creating a Many-To-Many relationship, but, it will not support entire feature of Many-To-Many concept. In other words, using Master-Detail Relationship for creating Many-To-Many Relationship gives you an ideal feature of Many-To-Many. Here are the features which you will not get with lookup relaionship.

1. We talk about 'Junction' object, whose identify and existence depends on Master record. Meaning Master deleted should trigger details to be deleted. From Application perspective you do not need any visibility of Junction Object. In other words, application should magically connect Object A with Object B. That is it. In that sense Master-Detail works best.
2. You loose agreegate functionality, if you need one on Detail Object

If these features are not required or adjusted somehow by your custom code, then both options will work. But, Master-Detail solution is always the ideal solution.