Master-Detail Relationship in Salesforce
Master-Detail relationship in Salesforce means a parent-child relationship between any two objects in which the parent object controls some certain behaviour of detail object i.e. child object.
Some Features of Master-Detail Relationship
- It is a strongly coupled Relationship.
- Parent object record is required on child object record.
- The standard objects cannot be child objects.
- Whenever you delete the parent object record then the child object record which is related to the parent object will automatically delete. It is known as Cascade deletion of records.
- The roll-Up summary field is only available for the parent object.
- You can create a maximum of 2 Master-Detail relationships for any object.
- The Owner field on the detail object is not available but it is automatically set to the owner of the associate master object record.
- Custom object as detail object in a master-detail relationship cannot have sharing rules, manual sharing, or queues, as these require the Owner field.
- The detailed object records follow the security and sharing setting of the master object record.
- This relationship can manage between ‘standard - custom objects’ and ‘Custom - Custom objects’.But not with ‘standard - standard objects’ because standard objects never be a child or detail object. But custom objects can be parent or child objects.
- When we undeleting master object record then automatically child object record associated with that master object record gets undeleted.
- Master-Detail relationship field is not required on child objects.
Don't forget to check out: Learn All About Salesforce Managed Services vs In-house Team
- You can create your Master-Detail Relationship Field on child objects only.
- Firstly you have to select your child and parent object then proceed further.
- You can not create a Master-Detail Relationship Field on any object when there will be any record already present on a child object.
How to create Master-Detail Relationship
Step - 1: Go to the ‘object manager’.
Step - 2: Select your child object on which you want to create your Master-Detail Relationship. Here I select ‘Company’ as my child object.
Step - 3: Click on the ‘Fields and Relationships’.
Step - 4: Click on the ‘New’ button to create the Master-Detail Relationship field.
Step - 5: Now select the ‘Master-Detail Relationship’ data type.
Step - 6: Click on ‘Next’.
Step - 7: Select Parent Object in the ‘Related to’ field. Here you can select any standard or Custom Object as a parent object according to your need. Here I select the ‘Account’ object from the drop-down menu as the parent object.
Step - 8: Click on the ‘Next' button.
Step - 9: Fill in the details -
- Field Label - you can give any name here according to your requirement. Here I gave ‘Account’ name. Mostly we give object names for master-detail relationships.
- Field Name - It automatically takes a Field Label name.
- Description - Describe your field details here. It is an optional field.
- Help Text - Give information about this field. It is also an optional field
- Child Relationship Name - ‘Companies’ Here your child object name automatically gets populated.
- Sharing Setting - Here you can give read/write or read access for this Master-detail relationship field.
- Allow Reparenting - If you checked this checkbox then it will allow for reparenting your master-detail relationship field. It is by default unchecked by Salesforce itself.
- Auto Add to Custom report type - It is by default checked the checkbox. It allows this field for the custom report type.
Check out another amazing blog by Rajat here: How to Create User in Salesforce | The Developer Guide
Step -10: Here you can Establish Field level security for reference fields. If the field is a master-detail relationship then it automatically assigns visibility to all profiles.
Step - 11: Click on the ‘Next' button.
Step - 12: Add reference field to page layout. Here your field is by default add to the page layout of your object.
Step - 13: Click on the ‘Next' button.
Step - 14: Here you can add this object to the related list of account object layouts. And click on the ‘Save’ Button.
Hence your Master-Detail relationship field is created successfully. And it is available in the ‘Field and Relationships’ of your child object.
I hope this information is helpful for you.
Thank you !!!