[SalesForce] What are the implications of using a reparentable master-detail relationship instead of a lookup

Since the Summer 12 release of salesforce it's been possible to set the "Allow reparenting" attribute on master-detail fields. This somewhat blurs the traditionally clear line of when to use a master-detail relationship and when to use a lookup relationship.

In particular, what, if any, are the differences between using a lookup with Delete this record also and a master-detail with Allow reparenting?

Best Answer

A lookup (with Delete this record also) and master-detail share a large number of similarities:

  • Deletion of the related record causes a cascade delete that does not invoke triggers.
  • Both types of relationships are automatically indexed.

There are some trivial differences:

  • Lookups are not required by default, where master-details are always required. Lookups can however be made required to share this behavior.

And there are some potentially major differences:

  • Lookups do not support rollup summary fields (although there are community solutions available).
  • Detail records do not have an owner, and thus do not have an ownerId field.
  • Detail records cannot independently participate in sharing, the access to them is always controlled by the access level (require read vs write to edit detail records) set when defining the relationship. Records related via lookups have wholly independent sharing from the related record.
  • Master-detail relationships cannot be to an object of the same type (e.g. MyObj_c to MyObj_c).
  • You can have no more than 3 levels of master-detail relationships, meaning a parent, child, and grandchild object. On the other hand you can built almost infinitely complex networks of lookup relationships.
  • There can be no more than two master-detail relationships on a object, and the first of the two has special behavior:

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.

In the end which to select often comes down to how you want to impact your sharing and security model. Lookups allow much greater flexibility here, but often this will require code and apex managed sharing to make full use of, although it can be leveraged with sharing rules.