Relationships associate objects with other objects.
For example, a relationship can link a custom object to standard object
in a related list, such as linking a custom object called Bugs to
cases to track product defects associated with customer cases. To
view the parent and child relationships among standard objects, see
the ERD diagrams in Data Model.
You can define different types of relationships by creating custom
relationship fields on an object. The differences between relationship
types include how they handle data deletion, record ownership, security,
and required fields in page layouts:
Master-Detail (1:n) — A parent-child relationship in which
the master object controls certain behaviors of the detail object:
When a record of the master object is deleted, its related detail
records are also deleted.
The Owner field on the detail object is not
available and is automatically set to the owner of its associated
master record. Custom objects on the detail side of a master-detail
relationship cannot have sharing rules, manual sharing, or queues,
as these require the Owner field.
The detail record inherits the sharing and security settings of
its master record.
The master-detail relationship field is required on the page layout
of the detail record.
You can define master-detail relationships between custom objects
or between a custom object and a standard object. However, the standard
object cannot be on the detail side of a relationship with a custom
object. In addition, you cannot create a master-detail relationship
in which the User or Lead objects are the master.
When you define
a master-detail relationship, the custom object on which you are working
is the detail side. Its data can appear as a custom related list on
page layouts for the other object.
Many-to-many — You can use master-detail relationships
to model many-to-many relationships 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. To create a many-to-many relationship, simply create a custom
junction object with two master-detail relationship fields, each linking
to the objects you want to relate. See the Salesforce online
help for details.
Custom objects with two master-detail relationships
are supported in API version
11 and later.
Lookup (1:n) — This type of relationship links two objects
together, but has no effect on deletion or security. Unlike master-detail
fields, lookup fields are not automatically required. When you define
a lookup relationship, data from one object can appear as a custom
related list on page layouts for the other object. See the Salesforce online
help for details.
To create relationships, use the user interface or Salesforce Metadata
API.