 Hello friends. I am Sanjay Gupta. I welcome you on Sanjay Gupta Tech School. In this video, I am going to demonstrate you how you can create master detail relationship in Salesforce Classic. Before starting, let me share you how you can search for Salesforce video tutorials. So you can search my name Sanjay Gupta on YouTube and you can follow my YouTube channel if you want to watch Salesforce training videos. So now we are logged in to Salesforce Classic. So here you can see I have student accounts and employees tabs. So if I click on accounts, sorry, if I click on employees. So here you can see right now I don't have any records, but if I click on students so you can see I have some records already created here. So three records are already available. Right. So first I'm going to create master detail relationship on employee object. Then I will create that relationship on student so that you can get to know if records are available what will happen and if records are not available then what will happen. So I'm clicking on setup searching for objects. So here you will see I have a student as well as employee object already created. So first I'm going to create master detail relationship on employee. So I'm clicking on new. So here you can see this master detail relationship data type is available. So first let's understand it properly. So if we read this description, it says a master detail relationship creates a spatial type of parent child relationship between this object, the child or detail. So whenever you want to create master detail relationship, then the field will be created on the child object. So in our case, employee is the child object. Then further it says and another object, the parent or master. So now we are going to create a master detail relationship for opportunity. So opportunity will be master object and employee will be child object. Right. So remember whenever you want to create master detail relationship, the field needs to be created on child object always. Then this first point says the relationship field is required on all detail record. So this field will be mandatory. You need to fill or you need to select a particular value in this master detail field. Then the ownership and sharing of the detail record are determined by the master record. So all the ownership and sharing rules will be applied as per the master record. When a user deletes the master record, all details records are deleted. So if a master record or you can say in our case if opportunity record is deleted, then all the related employee records will be deleted automatically. Last point says you can create roll up somebody fields on the master record to summarize the detailed records. So in case of master detail relationship, there is one more feature available, which is known as roll up somebody field. So you can create roll up somebody fields on master record that can summarize all the details records. So you can get to know about roll up somebody in my another video that is available in this playlist. So don't forget to watch that video if you want to understand roll up somebody field. Then at last it says the relationship field allows user to click on a lookup icon to select a value from a pop up list. So that pop up list will be for master object. So all master object records will be available in that list. Then the master object is the source of the values in the list. So I hope you understood this details. So now I'm going to create master detail relationship field. So I'm clicking on next. Here you can see it is asking for the object to which you want this child object to relate. So I'm selecting opportunity clicking on next. So field level will be opportunity field name will be opportunity. If you want to set description and help text you can fill it then the child relationship name is employees. Now this is important sharing setting. So here you can read this description. Select the minimum access level required on the master record to create edit or delete related detail records. So there are two sharing settings available. You can either select read only or you can select read or write read write as well. So you can read this description. Read only allows users with at least read access to the master record to create edit or delete related detail records. If you select read write then it allows users with at least read write access to the master record to create edit or delete related detail records. So accordingly sharing setting will be applied. Then one more option is available allow reparenting. So right now it is deselected. So it means if you want to change your master record then you need to select this checkbox as true. If you don't select it as true then once you selected a master record then later on you cannot edit that record. So after creating master detail relationship I will again come to this allow reparenting and we will check how it works. Then we have lookup filters. So right now I'm not demonstrating about lookup filter. If you want to watch it in detail you can follow another video that is available in this playlist. So right now we are just creating master detail relationship field so that we can understand it. So here you can see all the checkboxes are true for all the profiles because it is required field so it will be visible in edit mode. Then I'm clicking on next. So it should be available on page layout that's why it is by default check then we cannot uncheck it. I'm clicking on next. So here it is asking for the related list label. So on opportunity one related list will be available for each record. So opportunity has various layouts. So if you want to place this related list on all the layouts then you can click all the checkboxes as true. So I'm leaving it as it is and clicking on save. So here you can see master detail relationship field is created. Name is opportunity. It is looking up to opportunity object. So now if we move to our employee object and if we click on new. So here you can see opportunities are required field and it is having a lookup. So if I click on designation let's say scenes. Then employee ID I fill like this. Now if I click on save. So you will see an error message that you must enter a value because this opportunity is parent. Sorry, this opportunity is master detail field. So we need to fill this and here you can see for account. It is not showing any error because this is a lookup field. So now I'm clicking on this icon so that I can select a particular opportunity record. So here you can see it is showing a list. So I'm clicking a particular record and I'm clicking on save. So this way one employee record is created and it is looking up to this opportunity. Now if I open this opportunity in new tab. So on opportunity record you will see a related list that will show related employee record. So here it is. So one employee is related to this opportunity record. If you want to create more employee record. So here you can see this employee edit page is available and you can fill the details like. Manager employee ID. And opportunities by default populated because we are creating record from related list and you can click on save. So now you will see to. Sorry, we are on a employee. So we need to go on opportunity again. So I'm opening opportunity and if I scroll it down at the bottom you will see to employee records are related now. Right. So this way master detail box. Now if I move to employee record again. And click on edit. So here you can see it is not editable. Right. Now let's understand this why it is happening. So it is because of that allow reparenting feature. So if I click on edit. So here you will see that checkbox is unchecked. So now I'm clicking it as true and clicking on save. So now it is saving this change. Now again I'm moving here. Clicking on cancel. Doing a refresh. So now you will see. That opportunity field will be editable. So here you can change the parent. Record. So. You can see. You can see. I can select different opportunity here and I'm clicking on save. So this way I am able to change the opportunity record that is parent record. So if you if you selected allow parenting checkbox as true, then this feature will be available. Otherwise, once you selected the parent record, then you cannot edit or you cannot change that parent record. So I hope you understood about allow reparenting thing. Now if if we go to this student. So here you can see we have certain records already created. So on employee object, we were not having any record already created, but on student we have certain records that those are already created. So let's see what happens if you create master detailed relationship on one object, which is having some existing reports. So this time I'm opening student object. And I'm going to create new master detailed relationship. And if I open this student records, so you will see various fields are available here. So now we are going to create master detailed relationship. I'm clicking on next. So let me first edit this one. So here you can see we don't have any look up on master detailed relationship. We just have simple fields. Right. So now I am again selecting opportunity for student. So opportunity will be parent and student will be child. I'm clicking on next. Again, same settings I am applying. So I'm just clicking on next. Same. So here you can see it is showing an error message. So let's read this. It says cannot create master detailed relationship. Why so? You cannot create a master detailed relationship on an existing custom object if records already exist. So now I hope you understood why I demonstrated it in two ways. So on employee object, we didn't have any record. So that's why master detailed field was created successfully. But in case of student, we have three records already created. So it is not allowing us to create master detailed relationship field. Now it is showing the suggestion. So it says you must first create a lookup relationship and populate the lookup field with data in all records and then change the relationship type to master detail. So why this is happening because whenever you create master detailed relationship field, so this field is a mandatory field. So if you have records that are already available and you try to create master detailed relationship, then that field will be blank for existing records. It cannot be happened. So what it is suggesting first create lookup relationship, then fill all the lookup fields and then convert that into master detailed relationship. So this is the option available for this kind of scenario. So I'm clicking on back choosing lookup relationship. So from this list, just let me go to previous way. So I selected lookup. Now I'm selecting opportunity object has been clicking on next filling all the details that are required. So it should be visible and editable for all clicking on next again next and save. So now you can see here lookup relationship field is created. So still now we don't convert lookup into master detail. So first we need to open all the records. So here if I go to student. So three records are available. So I need to edit each one. And I need to populate value on that lookup field for each of the record. Then I can convert that lookup into master detail. So first is modified. Now I'm going to edit second one. So I'm selecting same opportunity record for all student records so that we can see in opportunity related list. Whether all three records will be available under a single opportunity or not. So this is the third one. So for all three records I selected edge SLA opportunity record. So all three records are now filled up. They have lookup values. Now if I try to edit this lookup field and I change field type to master detail. So it will convert successfully. So I'm leaving all the properties as it is and just click on save. So now you will see that that lookup is converted into master detail relationship. And if I open any of the record, let's say I refresh this open record. And if I click on edit. So here you can see this opportunity is not editable because we are not checked that allow reparenting checkbox as true. And now it is master detail so we cannot change it. Right now I'm clicking on cancel and I want to move to this opportunity. Record and let's see the related list. So here you can see all three students record are related here. So friends this way master detail field or data type works. I hope you understood in both the scenarios when we have records or we don't have any record. So if we have records we need to create lookup first then populate all the lookup fields in each of the record then convert that lookup into master detail. And if you are creating master detail at the first time for your object that doesn't have any record then it will be created successfully in your first attempt. So I hope you understood whatever I demonstrated in this video if you want to follow Salesforce training videos. You can search my name Sanjay Gupta on YouTube and you can follow my YouTube channel. Thank you for watching this video.