Use relationships to associate an object with other objects in Salesforce.
This type of relationship closely links objects together such that the master record controls certain behaviors of the detail and subdetail record.
Behaviors of master-detail relationships include:
- Deleting a detail record moves it to the Recycle Bin and leaves the master record intact; deleting a master record also deletes related detail and subdetail records. Undeleting a detail record restores it, and undeleting a master record also undeletes related detail and subdetail records. However, if you delete a detail record and later, separately, delete its master record, you cannot 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 subdetail records is not 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.
- The security settings for the master record control the detail and subdetail records.
- The master-detail relationship field (which is the field linking the objects) is required on the page layout of the detail and subdetail records.
- The master object can be a standard object, such as Account or Opportunity, or a custom object.
- As a best practice, don't exceed 10,000 child records for a master-detail relationship.
You can use master-detail relationships to model many-to-many relationships between any two objects. A many-to-many relationship allows each record of one object to be linked to multiple records from another object and vice versa. For example, you may have a custom object called “Bug” that relates to the standard case object such that a bug could be related to multiple cases and a case could also be related to multiple bugs.
This type of relationship links two objects together. Lookup relationships are similar to master-detail relationships, except they do not support sharing or roll-up summary fields.
Salesforce objects include lookup fields that allow you to associate two records together in a relationship. For example, a contact record includes an Account lookup field that represents the relationship between the contact and its associated organization. The object that contains the lookup field is the source object, while the object the lookup points to is the target object.
With a lookup relationship, you can:
- Link two different objects.
- Link an object with itself (with the exception of the user object; see Hierarchical). For example, you might want to link a custom object called “Bug” with itself to show how two different bugs are related to the same problem.