About Me

My photo
PLANO, Texas, United States

Friday, September 25, 2020

Salesforce Object Relationships

 You can define different types of relationships by creating custom relationship fields on an object.

  1. Master-detail

  2. Many-to-many

  3. Lookup

  4. External lookup

  5. Indirect lookup

  6. Hierarchical

  7. Self Relationship

Master-detail

A master-detail relationship is a strong relationship. Create a Master-detail relationship if you want to have a tight relationship between child and parent. Let's say an example of Invoice & Invoice line item. No Invoice LineItem exists without Invoice. Behaviors of master-detail relationships:

  • Deleting a master object record will delete all child records and restore will make a restore of child records.

  • By default, records can’t be reparented in master-detail relationships, however, the “Allow reparenting” option in the master-detail relationship definition, will allow repenting.

  • The Owner field on the child records is not available and is automatically set to the owner of the master record. Custom objects on the “detail” side of a master-detail relationship can't have sharing rules, manual sharing, or queues, as these require the Owner field.

  • Child Inherits Security from Master. You can’t set permissions on the detail record independently.

  • Each custom object can have up to two master-detail relationships

  • Standard objects can't be on the detail side of a custom object in a master-detail relationship.

  • You can have up to three custom detail levels.

  • You can't create a master-detail relationship if the custom object already contains data. The reason is the master is required in master-detail and if any existing data is there, you will not have a parent.

  • Roll-up summary fields can be created in master-detail.

  • The child inherits the Look and feel from the Parent.

Many-to-many

Many-to-many relationships can be defined using Junction Object. A Junction Object is an object having two master detail relationships. Lets a bug can be linked with different cases and one case can have multiple bugs. This kind of scenario can be taken care of using Many-to-many relationships.  Behaviors of Many-to-many relationships:

  • The first master-detail relationship you create on your junction object becomes the primary relationship and  second master-detail relationship you create on your junction object becomes the secondary relationship. 

  • Look and feel: The junction object's detail and edit pages use the color and any associated icon of the primary master object.

  • The junction object records inherit the value of the Owner field from their associated primary master record.

  • A junction object can't be on the master side of another master-detail relationship.

Lookup

Use lookup relationships when we want to link two objects loosely means a child object can exist without a parent object. Let's say Project and Resource. Multiple resources can be worked under one project. Also, the resource can be without a Project.  Behaviors of Lookup relationships:

  • By default, a parent record is not required, however you can make it required from the relationship.

  • If the parent record in a lookup relationship is deleted, the field history tracking for the child record does not record the deletion. 

  • Clear the value of this field. You can't choose this option if you make this field required. Use this Option when Parent is not always needed

  • Don't allow deletion of the lookup record that's part of a lookup relationship. Use this option when you want to ensure not to delete the parent if this is linked with the child object.

Hierarchical

  • A special lookup relationship available for only the user object. 

  • It lets users use a lookup field to associate one user with another that does not directly or indirectly refer to itself. 

  • For example, you can create a custom hierarchical relationship field to store each user's direct manager.

Self Relationship

  • A special lookup relationship is when you can create a relationship from an object to itself.

  • However, a record can indirectly relate to itself. For example, the Holiday Promotion campaign can have the Direct Mail campaign selected in the lookup relationship, and the Direct Mail campaign can have the Holiday Promotion campaign selected in the lookup relationship.


Relationships on External Objects

  • External lookup

    • An external lookup relationship links a child standard, custom, or external object to a parent external object. 

    • Lookup filters aren’t available for external lookup relationship fields.

    • Lookup search isn’t available for external lookup relationship fields. 

    • Depending on the availability of the external system, related lists of child external objects may load slowly when users view the parent record detail pages.

  • Indirect lookup

    • An indirect lookup relationship links a child's external object to a parent standard or custom object. 

    • When you create an indirect lookup relationship field on an external object, you specify the parent object field and the child object field to match and associate records in the relationship. 

    • Indirect lookup relationship fields can be created on external objects only.

    • Only objects that have a custom field with the External ID and Unique attributes are available as parent objects in indirect lookup relationships

    • Lookup search isn’t available for indirect lookup relationship fields. To edit an indirect lookup relationship field, manually enter the value of the target field of the parent record.


Converting Relationships

  • You can convert a master-detail relationship to a lookup relationship as long as no roll-up summary fields exist on the master object.

  • Converting a master-detail relationship to a lookup for a custom object on the “detail” side changes the organization-wide default for the object to public read/write.

  • You can convert a lookup relationship to a master-detail relationship if the lookup field in all the records contains a value.

  • Converting a lookup to master-detail-relationship changes the organization-wide default to Controlled by Parent and the sharing model is updated to public read/write.

1 comment: