 Hello friends. I'm Sanjay Gupta. I welcome you on Sanjay Gupta Tech School. In this video, I'm going to demonstrate you about lookup relationship in Salesforce. Before starting, let me show you how you can search on YouTube, search my name. My channel will be there. You can follow it to watch various Salesforce related videos. Now, in this video, I'm going to demonstrate you about lookup relationships. So I'm searching for existing objects. So I'm going to create lookup relationship on employee. So lookup relationship can be created through a custom field so you can click on new to create a custom field. And here you can see the option is available as lookup relationship. So first understand this what lookup relationship is. So here you can read the description. It says creates a relationship that links this object to another object. So it means if you want to link two objects, then you can create lookup relationship. So we are going to create lookup relationship on employee and we can link it with another object. So in this demonstration, I'm going to link employee with account object. So whether it says the relationship field allows users to click on a lookup icon to select a value from a pop up list. So this lookup relationship will create a field and their lookup icon will be available. And if you click on that icon, the pop up list will appear and you can select the other object values as the other object is the source of the values in the list. So whenever you click on the lookup icon, it will show all the values or all the records that are available in the source object. So source object will be the account and a target will be the employee or you can say parent will be the account and child will be the employee. So now I'm going to create this lookup relationship field. I'm going to link it with account. So while creating employee record, we can select account as a lookup field value. So here API name will be account description and help text you can fill as per the requirement. Then this is the child relationship name that you can use. So you can read this help text the child relationship name is an internal reference and is used for integration purpose. Be careful when changing the child relationship name as it may affect existing integrations. So we will discuss about it in later videos. So let's not discuss it here because it is something different. Next is the option required. So if you want this field to be required while saving a particular record so you can check this checkbox. I'm making it unchecked because I don't want to make it require. Now, next is what to do if the lookup record is deleted. So whenever you are creating employee record, so you need to select account record for this lookup. So first thing what happens when you delete the selected account record. So there are two options. It will clear the value of this field. And second says, don't allow deletion of lookup record that's part of a lookup relationship. So if you choose second option, then you cannot delete the parent record that is part of this lookup relationship. If you choose the first option, then the parent can be deleted and the lookup relationship will be cleared out. Further it says you can't choose this option if you make this field required. So if we click on this option required, so you can see we cannot select this option. We will be having this option only because lookup field is required so it should have some value. So you cannot delete the parent record that is part of lookup relationship if it is checked. So right now I'm making it optional and selecting this option. Also, I'm not explaining lookup filter as of now. You can watch another video related to lookup filter to understand this. I'm making this field visible for all the profiles. Then it is saying, do you want to place this field or employee layout? Yes, I want. Now here it is asking for the related list. So account will be on the master side and employee will be on the child side. So on account layouts, a related list will be added automatically if we check these checkboxes. So account object has four layouts and we want this employee related list to be available on all four layouts. So I'm making these checkboxes as true or leaving it as it is so that related list will be up here. Now I'm clicking on save. So this way we created lookup field. Here you can see lookup to account. So lookup to account is created. Now we can create the records. So I'm opening this employer tab. So right now there's no records. So I'm going to create new one. I have to fill employee ID. Then I'm selecting country as India. CTS Delhi. Designation sales manager. This is the data. So here you can see this is the lookup relationship. So lookup is looking up to account. This is the label and this is the lookup icon. So it will open a new window from where you can select the account records. So I'm selecting a particular account record test email account and clicking on save. So this way I created employer record and that is having lookup to account. And account test email ACC record is linked with this record. Right now if you want to open this one so you can right click and open this in new tab. So this is the account record that is linked with that employee record. And if you scroll it down so at the bottom you will see the related list. So this is the related list that is added automatically because we selected the checkbox while creating the lookup. So this is the employer record that is linked with this account. So count is the parent and this employee is working as a child. Right now we need to see what happens when we delete this account record. Right. So I'm going to delete this. So the account is deleted. Now I'm refreshing it. You will see the account lookup is automatically blank out. Right. This is because we selected the radio button. Yeah, this one we selected this one. What to do if the lookup record is deleted so lookup record that is the account is deleted. So it is clearing the value of this field. Right now I'm selecting this one. Don't allow deletion of the lookup record that's part of a lookup relationship. And I'm clicking on save. Now I'm clicking on edit clicking on lookup icon and selecting. Another account record and saving it. Right. So I selected this one opening. So this is open now if I try to delete this one. So it will throw an error. First, let's check related list. So this record is having the employer record as related. And also notice that you can also create new employee record from here also. You can click here and you can create another one. You can see account is by default populated here and I'm clicking on save. So this time that account will be having two related records. Here you can see six or seven. Right. And if we see employee so here two records are available. Now what happens when I delete this account record. So I'm clicking on delete clicking on OK. You will see an error message is available here. It is saying you attempt to delete Burlington Textiles Corporation of America could not be completed because it is associated with the following employees. If the following table is empty. It is because you do not have access to the record restricted in the tape. Right. So this is because we selected the second radio button. This one. So now I hope you understood the difference between these two. What happens when we delete the parent record. So if you select the first option then that can be deleted. If you select the second option then parent record cannot be deleted. Right. So this way look up relationship works in Salesforce. By default it is optional and you can also make it required by selecting this checkbox. So I hope you understood how look up relationship works in Salesforce. If you want to watch more related videos you can search me on YouTube. Thank you for watching this video.