Many-to-many relationships
Using master–detail fields, we can set up the so-called many-to-many relationships, which are a way to link a given record to more than one record using Junction objects.
When do you need it? Imagine that you want to link a Case with multiple Assets:
Many-to-many relationships in action
By using a many-to-many relationship, you can link a given Case to more than one Asset record.
The Junction object is a custom object that holds two different master–detail fields: the first master–detail field created is promoted to be the primary relation and the primary master record masters deletion, undeletion, and sharing the look and feel (such as the icon and page color) of the child record (in the previous picture, we can say that Asset is the primary record). The second master–detail on the Case is the secondary relation, which does not master any particular behavior.
Lookup relationships
The lookup field is similar to the master–detail relation, as it is used to link two objects without having the same strong binding between the parent and child records.
This means that sharing is not inherited, you cannot have roll-up fields, the child record has its own owner, and if you delete the parent record, then the child is not automatically deleted, and you can look up the same object type.
Creating a lookup field is quite similar to creating the master–detail type:
Lookup field configuration
The only difference is that you don’t have the Access section, just the What to do if the lookup record is deleted? option. If the parent record is deleted, you can choose to blank the field or throw an error so that the user is forced to update this relation before deleting the parent.
Field history tracking won’t record the lookup field’s deletion.
As lookup is not a required field (unlike a master-detail field), you can decide to put it as Required.
Filters apply the same way that we saw earlier when we looked at the master–detail field type.
If the main object is a custom object, then you can ask Salesforce Support to enable the Delete this record also option, which makes the lookup close to a master–detail relation, at least regarding the deletion behavior: this is called cascading delete.
Be aware that cascading delete allows a user to delete a child record they may not have access to.
Lookups can reference the same object type (which is not allowed in master–detail relationships), creating a so-called self-relationship: the only limitation is that you cannot look up a record with itself (this is called a circular reference).
You can convert a lookup relation into a master–detail relation only if the child records have a field for the master record, whereas you can convert a master–detail into a lookup only if you don’t have any roll-up field on the master object. A special kind of lookup relationship is the self relationship—that is, a lookup that points to the same object type it is originating from. For example, the Account, Case, and Campaign objects all have a Parent lookup field that points to the same object type.