Difference between revisions of "Master-Detail relationship"
imported>Aeric m (Text replace - 'Setup > Customize > ' to 'Designer > Data & Presentation > ') |
imported>Aeric m (Text replace - 'Data & Presentation > Objects' to 'Data > Objects') |
||
Line 18: | Line 18: | ||
:[[File:Updatefield-masterdetailoption.gif|right|thumb]] | :[[File:Updatefield-masterdetailoption.gif|right|thumb]] | ||
To create a Master-Detail relationship: | To create a Master-Detail relationship: | ||
#Click '''Designer > Data | #Click '''Designer > Data > Objects > {object} > Fields''' | ||
#Choose one of the following options: | #Choose one of the following options: | ||
::'''Edit an existing [[Lookup]] field''', and click the [Master-Detail Relationship Enabled] checkbox | ::'''Edit an existing [[Lookup]] field''', and click the [Master-Detail Relationship Enabled] checkbox | ||
Line 41: | Line 41: | ||
If no [[Rollup Summary Fields]] exist, the Master-Detail relationship can be disabled, as follows: | If no [[Rollup Summary Fields]] exist, the Master-Detail relationship can be disabled, as follows: | ||
#Click '''Designer > Data | #Click '''Designer > Data > Objects > {object} > Fields''' | ||
#*Edit an existing [[Lookup]] field | #*Edit an existing [[Lookup]] field | ||
#Uncheck the [Master-Detail Relationship Enabled] checkbox | #Uncheck the [Master-Detail Relationship Enabled] checkbox |
Revision as of 00:05, 3 June 2011
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.
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
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:
- Click Designer > Data > Objects > {object} > Fields
- 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:
- Do not create the Master-Detail relationship
- Notify the user that the Detail object contains existing records
- 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:
- Do not create the Master-Detail relationship
- Notify the user that the Detail object contains existing records
- 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:
- Click Designer > Data > Objects > {object} > Fields
- Edit an existing Lookup field
- Uncheck the [Master-Detail Relationship Enabled] checkbox
Considerations
Requirements and Restrictions
- The Master-Detail relationship option can be enabled on a Lookup field in a Custom Object
- 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
- A Master-Detail relationship can be disabled if no Rollup Summary Fields exist
- 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
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