Look ups and Master Detail

Look ups and Master Detail

We were done with just the two fields Auto Number and Formula Field, In this section we will move on and consider the other fields. Moving on with the fields lets consider:

Lookup Relationship:

Lets break it down so that we could actually understand this. What is a lookup? Something like looking up the Dictionary or the Phone Book? exactly that is what it is up to some extent. It took me some time to actually understand what these were. Unless you implement them it would be tough to know the difference between the Lookup Relationship or the Master-Detail Relationship. Consider this I am a customer and you have a business and would like to keep a record of customers and as to what Company they work for.

What will you do to achieve this? You can use two measures : The dumb way: Create a customer object/table and have the fields for consumers and as to where they work and details of the work place. The smart way: Create two different tables each for Customers and the place where they work. And on the customers object/table put a field place a reference that points to the place this customer works.

So, the obvious question that might arise would be that why break a single table into two different tables, and what difference does it really make. This very line will clear your doubt if you have.Suppose we have this single table then for every Customer creation we will have to fill in the individual details of the company. Now suppose a customer changes his company now we need to edit the company details contained in the Customer Detail.Yes all those fields that belong to the Company on the Customer Object/table. Okay what if the Company of size 500-employees itself was relocating ? Visit individual customers and update the Information?? Not really you would like to do that.. What we could have done could have been to create the two tables and then simply update the information to the Company object and the Customers would be still referencing the same Company.

Now if the customer moves to different company then if the Company exists in the Company table then well and good else we create a Company by the name and reference the customer to this company. As employees add up to this new company, we would have to simply create a reference of this new customer to the company.

Master-Detail Relationships:

The name speaks for itself Master-Detail (something serious). There is not much of a difference between the Lookup and Master-Detail Relationships when it comes to usage they both behave just the same.

The Difference (Important): The difference between the Lookup and Master-Detail is asked in almost all Interviews. The differences will make you distinguish which is a Master-Detail and which is a Lookup. I will not relate these differences with what is available on other blogs. So here we go.

Suppose we have a Lookup relationship and a Master-Detail Relationship between two objects in two different scenarios. Then the differences we will notice would be the following:

The Mater detail relationship can be used for roll-up summary. While Lookup can not be used for that purpose.

The security of the Master is endowed to the detail side. Which means who ever has access to the master will have access to the detail. Unlike in Lookup. Each of the side has their very own security.

If the master record is deleted the detail record get deleted on own. Suppose we had deleted a Company then all its Employees would have been deleted If we had selected a Master-Detail relationship instead of a Lookup Relationship.

The reference field on the child can not be left blank when Master-Detail is being used, it is always required. While when a lookup is used, the reference field can be left blank until we have not set it to be a required field.

You change the type of data i.e you can convert lookup to Master-Detail under the condition that the reference field on the child is not Blank/Null. As Master-Detail the reference field can not be left Blank.

Related Articles

Responses