Types of Relations in Salesforce
Relations are utilized or used to establish connection between two or more objects. Salesforce provides different types of relations such as
a. Master-Detail Relations
b. Lookup Relation
c. Many -Many Relation (Junction object)
d. Hierarchical Relations
e. External Lookup Relations
It is one to many relationship between two objects. Master-Detail fields can be created only on Custom objects. Master-Detail fields can be created only on those custom objects on which there are no records in it. Master-Detail field is a required field. In one to Many relation, on many sides of the relation, Master-Detail field is created.Object on which Master-Detail Field is created that object we call it as child object /Detail Object/ Related Object. In one to Many relation of Master-Detail, Object to whose data master-detail field is referring that object is called master object/Parent Object. Whichever the record that master-detail field is referring to, That record Id is stored in the Master-Detail field. If the master record is deleted ,corresponding child records are also deleted. but deleted child records will not be displayed in the recycle bin. If we undelete the master record ,corresponding child records are also undeleted. Objects in which Master-Detail field is generated or created, That object won’t have any owner field in it. Whoever is the owner of the master record ,he will be the owner of corresponding child records.
Sharing Setting in Master Detail:
This will specify the minimum access level required on the Master record to create, edit, or delete related Child records.
If you choose this option,Allows users who has at least Read access to the Master record can perform create, edit, or delete operations on corresponding child records.
If you choose this option, Allows users who has at least Read|Write access to the Master record can perform create, edit, or delete operations on
corresponding child records.
If this feature is enabled, Child can change it’s master record after creation of the record of the child.
An object is often or can be a Master to any number of objects. On an object we can create only two master-detail fields. Child objects can be parent to any other objects upto three levels. If an object has two parents on it, it can not be parent to any other object.
Junction object is a custom object. Junction object has two master -detail fields on it. Junction object maintains Many to Many relation. First Master -Detail field created on the junction object is called primary master.
Second Master-Detail field created on the Junction object is called secondary master. If you delete any master record ,corresponding child records are deleted.If any master record has more than 200 child records in the junction object, then we cannot delete that master record.
It is a one-to-Many Relation. It is often created on both standard and custom objects. It is often created on both objects which contain data or which does not contain data. If you delete the master record,corresponding child records won’t be deleted. Owner of parent record and child record are often the same or different 40 lookup fields on an object can be created by us. It is an optional field. We can create self lookup on an object. Don’t Allow deletion of Lookup Record which is a part of Lookup relation. If you enable this option, the parent record which has a child using lookup cannot be deleted.
This can be created only on user objects. It is a one-to-one relation, This is used to create a relation between user to user.
Steps to create Hierarchical relation:
1.Click on Setup
2.Click on Build
3.Click on Customize
4.Click on User
5.Click on Fields
6.Click on Custom Fields & Relations
7.Select the new
8.Choose data type as hierarchical relation
9.Enter field Name and details
10.Add field level security
11.Add the to the pageLayout
Work around Process:
Steps to create Master-Detail on Custom Object which contains the data:
1.Create Lookup field choosing master object as parent.
2.Goto every record existing the child object and assign some value in the Lookup field
3.Change the data type from lookup to master-detail
4.Click on setup
5.Click on build
6.Click on Create
7.Click on Object
8.Click on Object Name
9.Click on Fields
10.Click on Choose the lookup field
11.Choose the Lookup field and click on edit