Relationships

Relationships

Lookup
In this two objects are loosely coupled. A Parent can have multiple child objects but it is not mandatory to have a parent for every child.
You can not have a roll-up summary
Master-Detail
In this Two objects are tightly coupled. Without a parent a child can not exist. i.e. Every child should have a parent and if a parent is deleted all the child objects gets deleted. This is Cascade delete.
master object controls the behavior of the dependent child object
You can have a roll-up summary in case of a master-detail relationship.
A roll-up summary field is used to display a value in a master record based on the values of a set of fields in a detail record.
we cannot create Master – Detail Relationship field for the child object which is having existing records
To create first we should create Look up relationship then populate the field value for all the records and then convert the look up relationship to master detail relationship.
If the parent object doesn't have Roll up Summary fields for the child object then we can convert m-d relation into lookup
If we delete only Master – Detail Relationship field from the child object and undelete it from the Recycle Bin then it will be converted to look up relationship.
Other types are
Standard Relationship : Salesforce came up with its own implementation of relationships between standard objects. There is no specific order in which the behave.
Hierarchy Relationship :  as name suggests, it is a role based relationship

Junction Object : All the above relationships are one to one but if there is any requirement for many to many relationship then we can use Junction object to achieve this.
any object can have two master-detail relationships. this object behaves as a junction between two masters, and two masters are related as many to many.
as this is not a special Relationship, all the master detail properties apply here.
If the parent objects don't have Roll up Summary fields for the child object then we can delete junction onbject
Later if we undelete the object, Master detail fields on the junction objects will be converted to look up Fields.

Relationship between Account and contact
this is a special kind of relationship in salesforce.
along with regular relationships salesforce has a "Standard relationship" which behaves in unique way.
in this scenario account field is not mandatory, behaves like a lookup but when you add an account and if that account is deleted, all the contacts related to it gets deleted, behaves like a master-detail relationship

relationships ends with "__r" 
  However for Person accounts, custom fields ends with "__pc" and 
  custom relationship ends with "__pr".

No comments:

Powered by Blogger.