Field Relationship
Salesforce Database are relational databases that allow to connect two table / objects with each other. We can define relationship using Custom fields.
Salesforce provide two types of Fields relationship:
1. Look-up Relationship (loosely coupled)
2. Master-Detail Relationship (tightly coupled).
Look-up Relationship
Lookup Relationship is a loosely coupled (links) between two objects. Lookup relationship are just like Master-detail just,
- They do not share security settings.
- Roll-up summary cannot be created in this relationship.
Features of Look-up:
- This relationship can be used for Self relationship.
- Child records do not delete with Parent record deletion, rather we have two options:
- Blank out relationship field values.
- Do not allow parent record to delete.
- Ab object can have 25 lookup relations.
Steps to link two object using Lookup:
Opportunity(Parent) to Demo (Child)
1. Go to Demo Object structure. (Setup --> Objects --> Demo).
2. Scroll down to Custom fields.
3. Select Lookup relation and hit next.
4. Select Parent object (opportunity).
5. Fill in the information and do not hit next.
Now, on the bottom of page. There is Lookup Filter.
Lookup filter basically provide an enormous feature to filter out records that are not suitable.
So let set it up one.
Its simple just click on Lookup filter and fill in the values.
Now, we can set up an lookup filter for Opportunity Probability >= 50%. That means, all the opportunities which has Probability less than 50% will not be allowed.
Now hit Next.
6. Manage the FLS for field.
Visible: Permission to have access on this field.
Read-only: Restrict the permission from editing a field.
Click next now.
7. Choose do you require to make field available on page layout.
Hit next.
8. At last, you can set the related list on Opportunity level i.e. parent level.
It will display all the page layout available on parent objects, and you can customize to whichever page you want to display the related list.
Also, we can set the Related List name.
Hit save!!!
Master-Detail Relationship
Master - Detail relationship closely links objects like Master controls certain behavior of detail object.
Features controlled by Master (parent) object as below:
- Deleting a child record will delete the child record and leave master record intact, but deleting a master record will delete its child records.
- Un-deleting the Master record will un-delete all the child record that delete with mater record. If we delete child record first and then master record, it will not un-delete child records.
- Only Admin can re-parent the child record. By selecting "Allow Re-parenting" option while setup relationships.
- Master record owner own's the detail object records.
- Detail object inherit the security setting and permissions from Mater record.
- Master-detail relationship field is required on Detail page layout.
We will guide how to setup an Master-Detail Relationship:
Lets connect Demo Object (Detail) with Opportunity (Master)
1. Go to Demo Object structure. (Setup --> Objects --> Demo).
2. Scroll down to Custom fields.
3. Select Master - Detail option and hit next.
4. Select Opportunity from the Drop Down list and hit next.
5. Fill all the required information and do not hit next.
6. We have lookup filter on this page, lets see what are these.
Well, filter criteria is to limit the number of Master record. So that user would see only those records that are eligible to create Detail object records.
Over here, we created a filter criteria that only those Opportunities which have Amount greater than equal to 50000, can only be listed in the dialogue box.
Now, hit next.
7. Now, we need to set FLS (Field-Level Security).
As Master-Detail field is an required field on Detail page layout, this field is visible to all the profile and cannot be set Read-Only feature to any profile, so directly hit next.
8. As we are in Master-Detail, we also couldn't remove it from any Page layout.
Just save the field and its done.
Please add your comments below...
Comments