AgileApps Support Wiki Pre Release

Difference between revisions of "Master-Detail relationship"

From AgileApps Support Wiki
imported>Aeric
imported>Aeric
Β 
(6 intermediate revisions by the same user not shown)
Line 1: Line 1:
{{Deprecated|<br>This choice used to be an option when specifying creating a Lookup field. The option has become redundant however, and has been removed. Now, [[Rollup Summary Fields]] and [[Subforms]] can be used for summary calculations on fields in detail records, and [[Cascade Rules]] can automatically delete those records when a master record is deleted. Those operations work across multiple related objects--not just those that have a particular kind of Lookup field. (This section is due to be rewritten to simply define the concept and point to those options.)}}
A Master-Detail relationship is a one-to-many association between two objects, where detail records only exist when there is a master record to point to.


==About Master-Detail Relationships==
Examples of Master-Detail relationships include:
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. Β 
:* Invoices, where ''items in an order'' are detail records, and ''pricing or discounts'' are fields in the master record (the invoice)
:* Timesheets, where ''employees'' are master records, and ''hours worked'' are detail records
:* Inventory, where where ''shoe style'' is a master record, while detail records specify the ''size and color'' of shoes in stock.


{{permissionRef|Customize Objects|manage Master-Detail relationships}}
For a more detailed example, consider an order management system, where the Master object is ''Orders'' and the Detail object is ''Order Items''. Together, an invoice can be prepared from those records. Each line in the invoice can display the number of items ordered, the unit price, and the line item total, using values taken from the detail records. Sales tax and sub-totals, meanwhile, can be calculated and stored in the master (invoice) record.


Master-Detail relationships can be used in these scenarios:
In addition, when an order is deleted in a system like that, then all associated line items should be deleted as well.
*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''.
In the {{EnterpriseBrand}}:
:* [[Rollup Summary Fields]] are used to do calculate the line item totals.
:* [[Cascade Rules]] are used to auto-delete detail records when a master record is deleted.
:* [[Subforms]] are typically used to view and modify detail records while entering or editing a master record.


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.
{{Note|There used to be an option to specify "Master-Detail relationship" when creating a Lookup field. That option became redundant, however, and has been removed. [[Rollup Summary Fields]] and [[Cascade Rules]] achieve the same goals, but they work across multiple related objects--not just those that have a particular flag set on the Lookup field that connects them.}}
Β 
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 '''[[File:GearIcon.png]] > Customization > 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 '''[[File:GearIcon.png]] > Customization > 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 {{type| }}
:*{{Type}}s are not eligible
*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
<!-- this is true for ordinary Lookup fields as well-->
*A Detail object cannot also be a Master object
*[[Self Reference Lookup]]s 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
Β 
===Permissions===
*Object-level access for Detail objects are controlled by [[Record Access Permissions]]
Β 
===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
<!--
===Multiple Record Ownership==
*Records in the Master object can have [[Multiple Record Owners]]
*Multiple record owners cannot be enabled for records in the Detail object
*Record ownership is hierarchical; the Master object [[Record Owner]] is the Record owner of the records in the Detail object
*[[Custom Access Criteria]] apply for Master and Detail objects
*The [[Merge Records]] option is not available
-->
===Record-level Actions===
;Record Ownership:
*The [[Record Owner]] of Master object defines the ownership of the Detail object
*:All of the Role-based [[Validations]] and [[Team 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: [[Manage_Data_Import#Detail_records_in_a_Master-Detail_relationship|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 (<tt>owner_id</tt>)
Β 
Β 
===Packaging===
{{:Packaging Objects in a Master-Detail relationship}}
Β 
===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

Latest revision as of 20:14, 30 July 2014

A Master-Detail relationship is a one-to-many association between two objects, where detail records only exist when there is a master record to point to.

Examples of Master-Detail relationships include:

  • Invoices, where items in an order are detail records, and pricing or discounts are fields in the master record (the invoice)
  • Timesheets, where employees are master records, and hours worked are detail records
  • Inventory, where where shoe style is a master record, while detail records specify the size and color of shoes in stock.

For a more detailed example, consider an order management system, where the Master object is Orders and the Detail object is Order Items. Together, an invoice can be prepared from those records. Each line in the invoice can display the number of items ordered, the unit price, and the line item total, using values taken from the detail records. Sales tax and sub-totals, meanwhile, can be calculated and stored in the master (invoice) record.

In addition, when an order is deleted in a system like that, then all associated line items should be deleted as well.

In the AgileApps Cloud platform:

  • Rollup Summary Fields are used to do calculate the line item totals.
  • Cascade Rules are used to auto-delete detail records when a master record is deleted.
  • Subforms are typically used to view and modify detail records while entering or editing a master record.

Notepad.png

Note: There used to be an option to specify "Master-Detail relationship" when creating a Lookup field. That option became redundant, however, and has been removed. Rollup Summary Fields and Cascade Rules achieve the same goals, but they work across multiple related objects--not just those that have a particular flag set on the Lookup field that connects them.