Saturday 22 November 2014

Salesforce Relationships


In salesforce you can  associates objects with other objects using relationship.
You can define different types of relationships by define custom relationship fields and different relationship also determine the approach of data deletion, record ownership, security.

Types of Relationship:

1. Master - Detail (1:n) : Its a parent child relationship in which Master object controls the behavior of child object like
a) When master record is deleted its related detail/child record also gets deleted.
b) Owner field on detail/child object is not available and its owner is automatically set to owner of its Master object record.

c) Custom object of detail side of Master Detail relationship do not have sharing rule, manual sharing as these require Owner field.

d) Detail record inherit the sharing and security settings from its master record.
e) Master - Detail relationship field is required on page layout of the detail record.

f) By default detail records can not be re-parented, however administrator allow re-parenting by enabling "Allow re-parenting " option in the master detail relationship.

Note : You can define Master - Detail relationship between custom objects or between custom object and standard object but standard object can not be on the detail side.
Note : You can also not create master detail relationship where User or Lead objects are masters.

 * You can not create Master Detail relationship if custom object already contains data. To create Master Detail relationship first you need to create a look-up field and then converting them to Master detail if look-up field in all records contains a value.
* You can not delete a object if it is on Master Side of Master - Detail relationship and if you delete a object that is on detail side of Master - Detail relationship then relation is converted into look-up.
* Deleting Master record also delete related record.
* Undeleting Master record also undelete detail record.
Deleting detail record moves it to recycle bin.
* Undeleting detail record restores it.
* If you delete detail record and then separately delete Master record then you can not undelete related record because there is no Master record.


2. Many to Many : You can use Master Details relationship to create Many to Many relationship between two objects. This relationship allow each object to link with multiple record of other objects and vice-versa. Many to Many relationship requires a custom junction object with two master detail fields on page layout.



* Sharing access to junction object record is determine by the sharing access to both associated master objects records and Sharing setting option on relationship field. For example, if the sharing setting on both parents is Read/Write, then the user must have Read/Write access to both parents in order to have Read/Write access to the junction object. If, on the other hand, the sharing setting on both masters is Read-Only, a user with Read-Only rights on the master records would have Read/Write access to the junction object.

* user can not delete master object record if there are more that 200 detail object records.

* first master detail relationship you create becomes the primary relationship for junction object which affects
a) Look and Feel 
b) Record ownership

* second master detail relationship on junction object becomes the secondary relationship and if primary master-detail relationship is deleted then secondary becomes primary relationship.
* junction object can not be on Master side of another master-detail relationship.
* Many to Many provides two standard reports
1) "Primary master with junction object and Secondary master "
2) "Secondary master with junction object and Primary master"



3. Look-up Relationship :  This kind of relationship links two object. Unlike master-detail relationship look-up fields are not automatically required and data from one object appears as related list on page layout of other object.

* while creating look-up relationship we can select the option to make the field required.
* if look-up field is optional and look up record is deleted, we can select one of the below behaviors
a) "Clear the value of this field " ( this is default ) 
b) "Don't allow deletion of the look-up record that's a part of a look-up relationship"

* You can not delete an object or record in a look-up relationship if the combined number of records between two linked objects is more than 100,000.

No comments:

Post a Comment