Object Relationships

Object Relationship

Object relationships are special fields that connect two objects together. There are two main types of object relationships, Lookup, and master-detail.

Lookup Relationships

A lookup relationship essentially links two objects together so that you can “look up” one object from the related items on another object. Look-up relations can be one-to-one or one-to-many. Use lookup relationships when objects are only related in some cases. Objects in lookup relationships usually work as standalone objects and have their own tabs in the user interface. They, do not support sharing or roll-up summary fields.

With a lookup relationship, you can:

  • Link two different objects.
  • Link an object with itself (except for the user object; see Hierarchical). For example, link a custom object called Bug with itself to show how two different bugs are related to the same problem.

When you create a lookup relationship, you can set these options:

Make the lookup field required for saving a record, requiring it on the corresponding page layout as well.

If the lookup field is optional, you can specify one of three behaviors to occur if the lookup record is deleted:

Clear the value of this field This is the default. Clearing the field is a good choice when the field doesn’t have to contain a value from the associated lookup record.

Don’t allow deletion of the lookup record that’s part of a lookup relationship If you have dependencies built on the lookup relationship, such as a workflow rule, this option doesn’t allow the lookup record to be deleted.


Deleting a record that has child records isn’t allowed, except when the child records are soft-deleted (sent to the Recycle Bin). If all the child records of a parent record are soft-deleted, then the parent record is deleted. Furthermore, any soft-deleted children are then removed from the recycle bin and permanently deleted. Delete this record also Available only if a custom object contains the lookup relationship, not if it’s contained by a standard object. However, the lookup object can be either standard or custom. Choose when the lookup field and its associated record are tightly coupled and you want to completely delete related data. For example, say that you have an expense report record with a lookup relationship to individual expense records. When you delete the report, you probably want to delete all the expense records, too.


Choosing to Delete this record also can result in a cascade-delete. A cascade delete bypasses security and sharing settings, which means users can delete records when the target lookup record is deleted even if they don’t have access to the records. To prevent records from being accidentally deleted, cascade-delete is disabled by default. Contact Salesforce to get the cascade-delete option enabled for your organization. Cascade-delete and its related options aren’t available for lookup relationships to business hours, network, lead, price book, product, or user objects.

When you define a lookup relationship, you can include a lookup field on the page layouts for that object and create a related list on the associated object’s page layouts. For example, if you have a custom object called PTO Requests and you want your users to link a PTO request with the employee submitting the request, create a lookup relationship from the PTO Request custom object with the user object.

If the parent record in a lookup relationship is deleted, the field history tracking for the child record doesn’t record the deletion. For example, if a parent account is deleted, the Account History related list for the child account doesn’t show the deletion.

You can’t delete an object or record in a lookup relationship if the combined number of records between the two linked objects is more than 1,00,000. To delete an object or record in a lookup relationship, first, delete an appropriate number of its child records.

When you delete an object used by a lookup field, delete the field, too. To delete both the object and the field, use the Metadata API with a delete manifest that uses purge delete. Or, use Setup in the UI to delete the field first. Otherwise, the object can’t be deleted.

Master-Detail Relationships

In a master-detail relationship, one object is the master and another is the detail. The master object controls certain behavior of the detail object. Like who can view the details data. In a master-detail relationship, the detail does not work as a standalone. It is highly dependent on the master. In fact, if a record on the master object is deleted all its related details records are deleted as well. When you are creating a master-detail relationship, you always create the relationship field on the detail object.

Deleting a detailed record moves it to the Recycle Bin and leaves the master record intact; deleting a master record also deletes related detail and sub-detail records. Undeleting a detailed record restores it, and undeleting a master record also undeletes related detail and sub-detail records. However, if you delete a detailed record and later separately delete its master record, you can’t undelete the detail record, as it no longer has a master record to relate to.

By default, records can’t be reparented in master-detail relationships. Administrators can, however, allow child records in master-detail relationships on custom objects to be reparented to different parent records by selecting the Allow reparenting option in the master-detail relationship definition.

The Owner field on the detail and sub-detail records isn’t 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.

Detail and sub-detail records inherit security settings and permissions from the master record. You can’t set permissions on the detail record independently.

The master-detail relationship field (which is the field linking the objects) is required on the page layout of the detail and sub-detail records.

The master-detail relationship field (which is the field linking the objects) is required on the page layout of the detail and sub-detail records.

As a best practice, don’t exceed 10,000 child records for a master-detail relationship.

Each custom object can have up to two master-detail relationships and up to 40 total relationships.

The Related To entry can’t be changed after you save the relationship.

A profile or a permission set can have an entity, such as Account, with a master-detail relationship. A broken permission dependency exists if the child entity has permissions that the parent should have. Salesforce updates the parent entity for a broken permission dependency on the first save action for the profile or permission set.

Hierarchical Relationships

Hierarchical relationships are a special type of lookup relationship. The main difference between the two is that hierarchical relationships are only available on the user object. You can use them for things like creating a management chair between users.

Roll-up summary Fields

Roll-up summary fields calculate values from a set of related records such as those in a related list. You can create roll-up summary fields that automatically display a value on a master record based on the values of records in a detailed record. These detail records must be directly related to the master through a master-detail relationship.

You can perform different types of calculations with roll-up summary fields. You can count the number of detail records related to a master record, or calculate the sum, minimum or maximum value of a field in the detail records.

There are a few different types of summaries you can use.


Totals the number of related records.


Totals the values in the field you select in the field to aggregate the option. Only number, currency, and percentage fields are available.


Displays the lowest value of the field you select in the field to aggregate option for all directly related records. Only number, currency, percent, date, and DateTime fields are available.


Displays the highest value of the field you select in the field to aggregate option for all directly related records. Only number, currency, percent, date, and DateTime fields are available.

Leave a Reply

Related Posts

Ameer. M.A

Full Stack Developer

I am a Full Stack web developer, Progressive Web Apps (PWA) Developer, Hybrid mobile app developer, and ERP consultant from Kerala, India.

Ameer. M.A