Master-Detail relationship

From AgileApps Support Wiki
Revision as of 23:34, 4 March 2011 by imported>Aeric (Text replace - 'Setup > Customize > ' to 'Designer > Data & Presentation > ')
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
File:Master-detail-graphic.gif
Lookup field in the Detail Object (with Master-Detail relationship enabled)

A Master-Detail relationship is an association between two objects. When a Master-Detail relationship is created, it implies a tight relationship between the two objects. In essence, a Master-Detail relationship locks the objects together, so that every record in a Detail Object is associated with a record in a Master Object.

Lock-tiny.gif

Users that have the Customize Objects permission can manage Master-Detail relationships 

Master-Detail relationships can be used in these scenarios:

  • Invoices, where items in an order are records of the Master Object, and pricing or discounts are records in the Detail Object
  • Timesheets, where employees are records of the Master Object, and hours worked are records in the Detail Object
  • Inventory, where where shoes are records of the Master Object, and shoe style, size and color are records in the Detail Object
File:Detail.gif
Movies and Movie Orders in a Master-Detail relationship

For example, in an order management system, the Master object is Orders and the Detail object is Line Items.

Together, an invoice can be prepared from line items associated with an order. The invoice can display total number of items, and price. Sales tax and sub-totals can be calculated and included in the invoice.

If the order is processed through a workflow, then all associated line items are included with the order record. If an order is deleted, then all associated line items are deleted as well. If a user has Visibility permission for an Order-based View or Report, then the line items are visible to that user as well, i.e., records in Master-Detail relationships comply with any defined Visibility controls.

Configuration

To create a Master-Detail relationship:

  1. Click Designer > Data & Presentation > Objects > {object} > Fields
  2. Choose one of the following options:
Edit an existing Lookup field, and click the [Master-Detail Relationship Enabled] checkbox
The platform then verifies that the Master-Detail relationship can be Enabled:
  • If every record in the Detail object has an associated value for the lookup, then create the Master-Detail relationship
  • If any record in the Detail object does not have an associated value for the lookup, then:
  1. Do not create the Master-Detail relationship
  2. Notify the user that the Detail object contains existing records
  3. Ask the user to build the associations by selecting a value for each Lookup field in the Detail object
  • After this is completed, the user edit the Lookup field, and click the [Master-Detail Relationship Enabled] checkbox
Add a new Lookup field, and click the [Master-Detail Relationship Enabled] checkbox
The platform verifies that the Master-Detail relationship can be Enabled:
  • If the Detail object is empty (contains no records), then create the Master-Detail relationship
  • If the Detail object is not empty (contains one or more records), then:
  1. Do not create the Master-Detail relationship
  2. Notify the user that the Detail object contains existing records
  3. Ask the user to build the associations by selecting a value for each Lookup field in the Detail object
  • After this is completed, the user can edit the Lookup field, and click the [Master-Detail Relationship Enabled] checkbox


To disable a Master-Detail relationship:

If no Rollup Summary Fields exist, the Master-Detail relationship can be disabled, as follows:

  1. Click Designer > Data & Presentation > Objects > {object} > Fields
  2. Uncheck the [Master-Detail Relationship Enabled] checkbox

Considerations

Requirements and Restrictions

  • An Object can be a Master in no more than one Master-Detail relationship. (For more complex requirements, use the Composite Object APIs.)
  • When a Master-Detail relationship is created, all records added to the Detail object will have a relationship to the Master object
  • An index is automatically created in a Master-Detail relationship; this index is associated with the Detail object
  • When adding a record to a Detail object, the Lookup field is Required
  • When updating a record in a Detail object, the Lookup field is Read-Only
  • If a Rollup Summary Field (based on a Lookup field in a Master-Detail relationship) exists, then the Master-Detail relationship option in the Lookup field cannot be disabled
  • If a Master-Detail relationship is enabled, the Lookup field in the Detail object cannot be changed to point to a different object
  • A Detail object cannot also be a Master object
  • Self Reference Lookups cannot be converted to Master-Detail relationships
  • If two objects have a Parent-Child relationship (via Object Inheritance), these objects are not eligible for a Master-Detail relationship
  • Multiple Master-Detail relationships for a pair of objects is not allowed
  • If a Lookup field in a Detail object is deleted, then the Detail object index is also deleted
  • The Index created automatically via enabling the Master-Detail relationship should not be deleted by the user
  • If the Master-Detail relationship option in a Lookup field is disabled, then the associated Index is also deleted
  • Workflow actions can be applied to records in the Detail object

Permissions

  • Object-level access permissions for Detail objects are controlled by Roles

Rollup Summary Fields

  • If a Rollup Summary Field exists based on Master-Detail relationship, then the Master-Detail relationship cannot be disabled for that Lookup field


Record-level Actions

Record Ownership
  • The Record Owner of Master object defines the ownership of the Detail object
    All the Role/Validations/Data Sharing Policies are tied to the role of the master record owner
  • If a Master-Detail relationship is disabled, then record ownership of records in the Detail object reverts back to the user who created the original record
  • Update/View/Delete actions on a record in the Detail object are defined by the Record Owner of record in the Master object
    The owner of the record in the Master object receives all notifications (email notifications to the record owner, task ownership, record ownership changes, etc.)
Restoring Deleted Records
  • If the Master object is restored, then all associated Detail records are restored
  • If a Master object is deleted forever, then no records can be restored from the Master or the Detail object
  • If record(s) in a Detail object are deleted, and the Master object is restored, then the record(s) in the Detail object are not restored

Object Deletion

  • A Master object cannot be deleted unless all records in the Detail object are deleted

Data Import / Export

Data Import
  • Records can be imported into the Detail Object of of a Master-Detail relationship.
Learn more: Detail records in a Master-Detail relationship
Data Export
  • Export the Detail object to capture all information in the Master-Detail relationship
  • The actual Record Owner of the Detail object is exported (not the Record Owner associated with the Master object)

Views/Reports/Search

  • In Views/Reports/Search/Filter actions on records in Detail objects, the Record Owner is the owner of the Master object (owner_id)


Packaging

Notepad.png

Note:
The "Master-Detail relationship" option on a Lookup field has been deprecated. This section is provided for legacy objects that have a Lookup field for which that option has been selected.
Learn more: Master-Detail relationships

  • If a Detail object is added to a Package, the Master object is added (automatically) as a dependent object
  • If a Master object is added to a Package and if that Master object includes any Rollup Summary Fields, then the Detail object is added (automatically) as a dependent object
  • When a Tenant installs a Package, the Rollup Summary Fields limit defined in Manage Tenant Capabilities is honored
  • If the limit is exceeded, the installation process will stop and cannot proceed
  • In order to complete the installation, delete existing Rollup Summary Fields to reduce the total number to within the defined limit
  • After packaging, do not add or remove any Master-Detail relationships; doing so may cause unexpected results and/or loss of data

Inheritance

  • A Detail object can be a parent object in an Object Inheritance relationship; in this case, all children of the Detail object are considered to be children of the Master object


[[Category:Template:Features]]