Both Lookup fields and Master-Detail fields create a one-to-many relationship. This means the parent object can have multiple children. However a child cannot have multiple parents.

To allow the parent to have multiple children and the children to have multiple parents, a many-to-many relationship is needed.

To create a many-to-many relationship, you need a junction object. Some out-of-the-box examples of a junction object include Campaign Member (CM) and Opportunity Product.

CM allows a campaign to have multiple contacts, and for a contact to be associated with multiple campaigns. Examining the data model, the CM has two Lookup fields: one to Campaign, and the other to Contact.

Thus knowing when to use a junction object depends on whether you need to have a reciprocal relationship between two records.

Other considerations:

  • This approach shouldn’t be used as a starting point, as it generally makes things more complicated
  • It’s often better to use two Lookup fields instead of two Master-Detail fields (see Lookup fields vs Master-Details fields for details)

The takeaway
Junction objects are a great way to direct a bi-directional relationship between records.

But they should be used with caution as it can increase the technical complexity and can decrease the user experience.

Category:
Salesforce
Tags: