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
sfdc freshersfdc fresher 

lookup,master-detail and junction

could anyone give me sample scenarios when we go for lookup,master and junction
Rebecca Hendricks 3Rebecca Hendricks 3
that is a very complex question. As I am still new and learning myself, I will try and share what I have learned already.

All three are similar in that they all help connect two different objects in Salesforce.  The difference is in how they are connected, and what functionality is now available because of it.

This merely means that they are connected as one get's the information from another.  You can think of it like one spouse always having to ask the other about a friend's name. The object that has the lookup (object A) doesn't really "know" the information, they just reference whatever the lookedup object (object B) is telling them.  If Object B changes that information, then Object A will reflect it because they have "asked" for it.  A lookup reference is good to use if they are closely related to each other (a task displaying the user that created it, etc.).  As each item is still an independent item, they can have separate sharing rules, and you can decide if the field is required or not.

This means that the two objects are directly dependant on each other, almost "dependent" upon each other.  Imagine using Salesforce to track job applications. A Job Posting is the actual posting for the job being offered.  This object would need to know, amongst other things, the position that is actually being offered.  (We need a separate object for the job posting, as the position may have several openings - such as sales associates - or may become available again - incase the new VP decides to retire.)  Selecting a Master-Detail relationship allows you to do special calculations that are built-in to Salesforce called Rollup-Summaries.  This allows you to Count, Sum, find the Min, and find the Max for the field that was selected in the Master-Detail.  The relationship always needs to be created in the object that is to be considered the "child" (in this example the job posting), and the Rollup Summary is done on the "parent" (the position object).

This type of relationship automatically requries that the "parent" field not be blank.  So when creating the Job Posting, a Position must be specified.  It also automatically sets the sharing rules on the child object to use whatever the rules for the parent are.  There is currently no way to have a different sharing set for the child than the parent.

This is the one I'm least familiar with.  I believe this type of object is used when these two objects are not connected directly to each other, but have a common item together.  Imagine you have a Chocolate object, and a Flowers object.  Normally those two things have nothing in common.  However, on Valentine's Day they are very often combined together.  (They usually go together when a spouse has angered the other, but let's keep with the more positive scenario...)  If we wanted to connect them, we would then have to create a Valentine's Day object and have that be the item that connects the Chocolate object to our Flowers Object.  That's why it's called a Junction.
Dinesh GopalakrishnanDinesh Gopalakrishnan
LookUp RelationShip(1:n)
This type of relationship links two objects together, but has no effect on deletion or security.
->If you Delete Parent Record it won't make any impact in Child Record.Child Record has its Own OwnerShip.
->Self Lookup Is Possible.

Master-Detail (1:n)
A parent-child relationship in which the master object controls certain behaviors of the detail object.

->When a record of the master object is deleted, its related detail records are also deleted.
->Self Lookup Is Not Possible.

Junction(Many to Many)
You can use master-detail relationships to model many-to-many relationships between any two objects. A many-to-many relationship allows each record of one object to be linked to multiple records from another object and vice versa.
VarSha ChouguleVarSha Chougule

For Lookup Relationship:Lets consider below 2 objects-
Position: (Child)
Hiring Manager: (Parent)
Create the Lookup association between Position and Hiring Manager objects.
1. Lookup Relationship provides One to Many association between the records by default.
    (i.e. A parent record can have Many associated child records.--> Hiring Manager can have many Position open to fill up)
2. Upon creating the child record, Lookup field is optional by default. 
    (i.e. We may  or maynot select the parent upon creating the child record) 
3. Lookup Relationship provides the Re-Parenting option by default. (i.e. we can change the parent of the child record
4. Upon deleting the Parent record, child record will not be removed. It will be existed as it is.
5. We can make the Lookup field as Manadatory by selecting "Required" checkbox upon creating the Relationship field.
6. If the Lookup field is required upon creating the child record. Then If the user removes the Parent record, then salesforce doesn't allow to delete the Parent if any childs exist.
    Sol: We need to re-parent all the child to some other parent record and then delete the parent record.  
7. We can create the Lookup Relationship on an object which contains the records.
8. We can have max. of 40 lookup relationships per an object.
9. In Lookup Relationship, Parent and Child records will have the Owner fields.
    i.e. Sharing Settings and Security Settings will be independent of each other.  
10. By using Lookup Relationship, we can make a Standard object as a child object with your Custom Object as parent.

 Master-Detail Relationship->
Lets consider the below example- Candidate and Position are objects.Here Position is the Master and Candidate is Detail. If we delete position , then candidate will also be deleted.

    Location: Picklist
    Age : Number
    Position: (Master-Detail)

1. Master-Detail association will provides One-Many association between the objects by default.
    (i.e. A Parent record can have zero or more child records)
2. We can't create the Master-Detail relationship between the objects, where child object contains the records.
3. Upon creating the child record, selecting the Parent record is Mandatory. (i.e. Lookup field is a Required field)
4. Re-Parenting option is not available by default in Master-Detail association. 
    We need to enable it manually, by selecting the "Allow Re-Parenting" checkbox upon creating the field.
5. An object can have max. of 2 Master-Detail relationship fields.
6. Parent record will have the "Owner" field and Child record will not having the "Owner" field.
    (i.e Child record will be completely comes under the control of Parent record.) 
7. Sharing Settings and Security settings of the child record will be depends upon the parent record.
8. Upon removing the Parent record, all the associated child records will remove automatically.
9. We can't make a Standard object as the Child for a Custom object with Master-Detail association.

Many To Many Relationship:
In few cases, we have to map Many to Many association between two objects, Which provides One- Many association from both the sides.
        We have Two Objects Author and Book.
        An Author can participate while preparing the Multiple books (i.e. One to Many from Author To Book).
        A Book can be prepared by multiple Authors (i.e. One to Many Association from Book to Author)
In Salesforce, we can't map Many-Many to association between two objects directly.
We need to achieve this feature, by creating a Junction object. Which associated with both the Parents with Master-Detail association.
Salesforce provides a set of junction objects, which has been created upon Salesforce CRM Application Development.
1. Between Campaign and Contact object, Salesforce provides Many-Many association by creating a junction object "CampaignMember".
2. Between Contact and Opportunity object, Salesforce provides Many-Many associated by creating a junction object "OpportunityContactRoles".
3. Between Opportunity and Product(Product2) object, Salesforce provides Many-Many association by creating a junction object "OpportunityLineItem".
4. Between Product and Pricebook(Pricebook2) object, Salesforce provides Many-Many association by creating a junction object "PricebookEntry".

Please mark as Best answer if this helped you. Thanks!!!
lovelesh sharmalovelesh sharma
Best answer as of now.
Suraj Tripathi 47Suraj Tripathi 47


First of all, the junction is different from the lookup and master-detail.
Because lookup and master-detail are kinds of relationship but the junction is the object.

Lookup -> Lookup means the foreign key in the reference of the normal database.
In which, both objects are loosely coupled.

Master-Detail -> MD for the tightly coupled relationship.
When you delete the parent record, the child record is deleted automatically.

Junction -> Junctions are those objects, which is created to remote redundancy from the database.
In junction, there is a lookup or MD relationship between two or more objects.

If you find your Solution then mark this as the best answer. 

Thank you!

Suraj Tripathi
Richard Fiekowsky 3Richard Fiekowsky 3
Also, as a practical matter, ceratin specific relationships between standard objects are lookup fields in the schema but behave like master-detail fields. This behavior cannot be changed, and of course standard fields' definitions cannot be changed either. Several of these are listed in including the Opportunity field on OpportunityLineItem.