Junction Object in Salesforce

A custom object with two master-detail relationships is called Junction Object. Junction objects are used to create many to many relationships between objects. A many-to-many relationship allows each record of one object to be linked to multiple records from another object and vice versa. One Object can have only two Master-Detail relationships.

For example, Let us assume that we have two custom objects – A and B. To provide the many to many relationship between A and B, we will need to create one more object let’s say it would be C, it will be called as junction object.

The first master-detail relationship you create on your junction object becomes the primary relationship. This affects the following for the junction object records:

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

Record ownership: The junction object records inherit the value of the Owner field from their associated primary master record. Because objects on the detail side of a relationship do not have a visible Owner field, this is only relevant if you later delete both master-detail relationships on your junction object.

Division: If your organization uses divisions to segment data, the junction object records inherit their division from their associated primary master record. Similar to the record ownership, this is only relevant if you later delete both master-detail relationships.

Note:

  • If we delete record A (First Master detail relationship is always primary) – then child record c will be deleted.
  • If we delete record B then in this case also child record C will be deleted.
  • If we delete record C then only C will be deleted , master record will not be deleted.
  • If child C has two Master record A and B, Where A is primary relation then Child record C will inherit the look and feel of Parent object A.