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
SK R.ax1448SK R.ax1448 

Master-Detail and Lookup

Hi All,

 

Can anyone please explain the below

 

1. What is Master-Detail and Lookup relations / Major difference b/w them ?

2. What is the significance/use of Master-Detail and Lookup ?

3. When to use Master-Detail and Lookup ?

 


Thanks a ton in advance !

 

Regards,

SK

 

Best Answer chosen by Admin (Salesforce Developers) 
codeshodecodeshode

Sure man,

 

  • Best example would be Required attribute. Look Up is variably required, (as per new releases you can make it a required filed at object level, and on VF page you can always make it required), but master detail is strictly required.

 

  • Another good one is, the Roll up summary, imagine you have a master object called total expense, and detail objects with differenet expense types. You can simply make a roll-up summary which adds up all these detail data and sums it up to Total expense field we will call it Amount. So easy isn't it

 

  • One more is Cascade delete, now in above example if your totla expense record is deleted, then whats the point of keeping youe detail data (obviously not). So in case of Look-Up you will have to manaully delete them. But in Master-Detail, all the child/detail records are automatically deleted once you remove master record

 

Hope this gives you a little insight, although there are a lot of such examples with different functionalities, but i'm sure you'll know it as you start working with it.

 

Thanks

[do mark it as a solution or give kudos if you think i helped you any bit. ;) ]

All Answers

codeshodecodeshode

Hey SK_R

 

This is a pretty famous question here in developer forum.

Still i would give you a little clue from my end.

 

Lookup relationship : Loosely coupled relationship

Master-Detail : Tightly coupled relationship.

 

  • In Master-Detail, when we delete the parent record, all child records are also deleted In Master-Detail.
  • A person who can view the master can see all the detail records of that master as the their is no owner on the detail side records and detail side gets its access properties from the master. Nothing of this sort happens in the Lookup relation as both objects have owners.
  • 1 detail can have maximum of 2 masters but no limit on the Lookup fields
  • Roll up summary field can be made on Master Detail relation.
  • Standard objects can never be on the detail side of the master detail relationship but no such thing in a Lookup relation.

Apart from this I'll give a link to another discussion on the same topic, the solution is really nice, please have a look :

 

http://boards.developerforce.com/t5/General-Development/Difference-between-Lookup-Relationship-and-Master-Detail/td-p/209011

pjcloudpjcloud

The line between the two is becoming more blurred, so perhaps it is becoming more difficult to distinguish. 

 

For instance, it used to be that Master-Detail fields were required, lookups weren't. 

 

Now, we can make lookups required (except for where certain parent objects are standard objects, User and Product, for instance). 

 

Master-Details always cascade delete. 

 

Lookup relationships can be made to either not cascade delete, block delete of the parent to prevent orphan children, or cascade delete (although cascading creates some permissions anomalies, so you must contact support to enable this feature). 

 

When choosing which to use, the feature the feature that gets overlooked a lot by people who are new to the platform is the inheriting of permissions access from parent to child in the Master-Detail relationship. The reason being is this: if I have a use case where I must grant access to parent data, but must not automatically grant access to the children, I can't use Master-Detail.

 

Another item that is important is reporting. And this, I confess, I don't understand very well, but the type of relationship you use changes the way that data is available across relationships, in reports. 

 

Start with the resource that Manish shared, get building, and then, if you come to a particular use case and aren't sure if you are designing correctly, come back and ask again. 

SK R.ax1448SK R.ax1448

Hi Manish,

 

Thank you for your reply.

 

Apart from these differences , what is the use / purpose of these relationships ?. When to choose Master-Detail, when to choose look up fileds ?.

Can you please give a real time scenario ?

 

 

Thanks in advance !

SK

 

codeshodecodeshode

Sure man,

 

  • Best example would be Required attribute. Look Up is variably required, (as per new releases you can make it a required filed at object level, and on VF page you can always make it required), but master detail is strictly required.

 

  • Another good one is, the Roll up summary, imagine you have a master object called total expense, and detail objects with differenet expense types. You can simply make a roll-up summary which adds up all these detail data and sums it up to Total expense field we will call it Amount. So easy isn't it

 

  • One more is Cascade delete, now in above example if your totla expense record is deleted, then whats the point of keeping youe detail data (obviously not). So in case of Look-Up you will have to manaully delete them. But in Master-Detail, all the child/detail records are automatically deleted once you remove master record

 

Hope this gives you a little insight, although there are a lot of such examples with different functionalities, but i'm sure you'll know it as you start working with it.

 

Thanks

[do mark it as a solution or give kudos if you think i helped you any bit. ;) ]

This was selected as the best answer
SK R.ax1448SK R.ax1448

Thank you very much for explaination.

 

 

Regards,

SK.