---
schema_version: "1"
id: 7b78b29bc4b9a10797b929cadd73fab53b7dbe1ca8114f62dd48c2380d842e95
title: Create a Many-to-Many Object Relationship
collection: admin
version: current
locale: en-us
portal_url: https://docs.salesforce.com/admin/current/en-us/platform/264-0-0/relationships_manytomany.md
canonical_url: https://help.salesforce.com/s/articleView?id=platform.relationships_manytomany.htm&release=264.0.0&type=5
source_site: help.salesforce.com
content_type: documentation
content_hash: 7ee906aeb06e86577b719cda26041bf8bb8f12980b2fca98f2a291cee9c910b4
description: 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 create 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. When modeling a many-to-many relationship, you use a junction object to connect the two objects you want to relate to each other.
products:
  - Salesforce Platform
  - Security
release: "264"
---
# Create a Many-to-Many Object 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 create 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. When modeling a many-to-many relationship, you use a junction object to connect the two objects you want to relate to each other.

### Required Editions

![Important](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-platform-extend_click-264-0-0-production-enus/5f7d9219-b7b1-4552-8891-f1aba9b289fc/images/icon_important.png)

Important Where possible, we changed noninclusive terms to align with our company value of Equality. We maintained certain terms to avoid any effect on customer implementations.

<table class="slds-table slds-table_bordered slds-max-medium-table_stacked slds-m-bottom_small edition">
        <colgroup>
          <col>
        </colgroup>
        <tbody>
          <tr class="">
            <td class="slds-cell-wrap" style="vertical-align:top;">Available in: both Salesforce Classic and Lightning Experience</td>

          </tr>
          <tr class="">
            <td class="slds-cell-wrap" style="vertical-align:top;">
              <p>Available in: <strong>Contact Manager</strong>, <strong>Group</strong>, <strong>Professional</strong>,
                <strong>Enterprise</strong>, <strong>Performance</strong>, <strong>Unlimited</strong>, <strong>Developer</strong>, and
                <strong>Database.com</strong> Editions
              </p>
              <p style="margin-bottom:0;">Reports aren’t available in
                <strong>Database.com</strong>.
              </p>
            </td>

          </tr>
        </tbody>
      </table> <table class="slds-table slds-table_bordered slds-max-medium-table_stacked slds-m-bottom_small permission">
        <colgroup>
          <col style="width:50%">
          <col style="width:50%">
        </colgroup>
        <thead class="slds-text-title_caps ">
          <tr class="">
            <th scope="colgroup" class="slds-cell-wrap" colspan="2" style="text-align:center;vertical-align:top;" id="d112054e99">User Permissions
              Needed</th>
          </tr>
        </thead>
        <tbody>
          <tr class="">
            <td data-label="User Permissions Needed" class="slds-cell-wrap" style="vertical-align:top;" headers="d112054e99 ">To create a many-to-many relationship:</td>

            <td class="slds-cell-wrap" style="vertical-align:top;" headers="d112054e99 ">Customize Application</td>

          </tr>
        </tbody>
      </table>

![Tip](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-platform-extend_click-264-0-0-production-enus/5f7d9219-b7b1-4552-8891-f1aba9b289fc/images/icon_tip.png)

Tip To get help from an AI agent on this task, use Setup with Agentforce. For more information, see [Data Model Management in Setup with Agentforce](https://help.salesforce.com/s/articleView?id=xcloud.setup_agentforce_data_model.htm&language=en_US).

Junction Object

A custom object with two master-detail relationships. Using a custom junction object, you can model a “many-to-many” relationship between two objects.

For example, you create 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.

How to create many-to-many relationships:

1. [Create the junction object](https://help.salesforce.com/s/articleView?id=platform.relationships_manytomany.htm&release=264.0.0&type=5).
2. [Create the two master-detail relationships](https://help.salesforce.com/s/articleView?id=platform.relationships_manytomany.htm&release=264.0.0&type=5).
3. [Customize the related lists](https://help.salesforce.com/s/articleView?id=platform.relationships_manytomany.htm&release=264.0.0&type=5) on the page layouts of the two master objects.
4. [Customize reports](https://help.salesforce.com/s/articleView?id=platform.relationships_manytomany.htm&release=264.0.0&type=5) to maximize the effectiveness of the many-to-many relationship.

Create the Junction Object

1. [Create a custom object to be your junction object](https://help.salesforce.com/s/articleView?id=platform.dev_objectcreate_task_parent.htm&release=264.0.0&type=5 "Track and store data that’s unique to your organization. Follow different steps, depending on which Salesforce experience you’re using.").
2. In the custom object wizard, consider these tips specifically for junction objects:
    - Name the object with a label that indicates its purpose, such as BugCaseAssociation.
    - For the Record Name field, we recommend that you use the auto-number data type.
    - Don’t launch the custom tab wizard before clicking **Save**. Junction objects don’t need a tab.

Create the Two Master-Detail Relationships

To create the two master-detail relationships:

1. Verify that the two objects you want to relate to each other exist. For example, you want to relate the standard case object to a custom bug object.
2. On the junction object, create the first master-detail relationship field. In the custom field wizard:
    1. Choose **Master-Detail Relationship** as the field type.
    2. Select one of the objects to relate to your junction object. For example, select **Case**.
        
        The first master-detail relationship you create on your junction object becomes the primary relationship. This relationship affects the following for the junction object records.
        
        - Look and feel: The junction object's detail and edit pages use the color and any associated icon of the primary master object.
        - Record ownership: The junction object records inherit the value of the Owner field from their associated primary master record. Because objects on the detail side of a relationship don’t have a visible Owner field, this inherited value is only relevant if you later delete both master-detail relationships on your junction object.
        - Division: If your org uses divisions to segment data, the junction object records inherit their division from their associated primary master record. Similar to the record ownership, this inherited division is only relevant if you later delete both master-detail relationships.
    3. Select a Sharing Setting option. For master-detail relationship fields, the Sharing Setting attribute determines the sharing access that users must have to a master record to create, edit, or delete its associated detail records.
    4. For the Related List Label that's displayed on the page layout of the master object, don’t accept the default value. Change the value to use the name of the other master object in your many-to-many relationship. For example, change the value to Bugs so users see a Bugs related list on the case detail page.
3. On the junction object, create the second master-detail relationship. In the custom field wizard:
    1. Choose **Master-Detail Relationship** as the field type.
    2. Select the other desired master object to relate to your junction object. For example, select Bug.
        
        The second master-detail relationship you create on your junction object becomes the secondary relationship. If you delete the primary master-detail relationship or convert it to a lookup relationship, the secondary master object becomes primary.
    3. Select a Sharing Setting option. For master-detail relationship fields, the Sharing Setting attribute determines the sharing access that users must have to a master record to create, edit, or delete its associated detail records.
    4. For the Related List Label that displays on the page layout of the master object, don’t accept the default value. Change this value to use the name of the other master object in your many-to-many relationship. For example, change this value to Cases so users see a Cases related list on the bug detail page.

Customize Many-to-Many Relationship Related Lists

For a many-to-many relationship in Salesforce, each master object record displays a related list of the associated junction object records. To create a seamless user experience, you can change the name of the junction object related list on each of the master object page layouts to have the name of the other master object. For example, you can change the BugCaseAssociations related list to Cases on the bugs page layout and to Bugs on the cases page layout. You can further customize these related lists to display fields from the other master object.

To customize the fields that display in the junction object related list on each master object page layout:

1. Edit the page layout of each master object that is related to the junction object. For example, modify the BugCaseAssociations related list for case records by editing the page layout for cases.
2. Edit the properties of the related list you want to modify. For example, on cases the BugCaseAssociations related list was renamed to Bugs, so select the Bugs related list.
3. Add the fields to display in the related list. You can add fields from the junction object itself, but more importantly, you can add fields from the other master object.
    
    Each field is prefixed with its object name in the window. In the related list itself, only fields from the junction object are prefixed with the object name; fields from the other master object aren’t.

![Note](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-platform-extend_click-264-0-0-production-enus/5f7d9219-b7b1-4552-8891-f1aba9b289fc/images/icon_note.png)

Note The junction object related list doesn’t include an icon on the master record's detail pages because the junction object doesn’t have a custom tab. If you make a tab for the junction object, the icon is included.

Customize Reports for Many-to-Many Relationships

Many-to-many relationships provide two standard report types that join the master objects and the junction object. The report types are:

- “Primary master with junction object and secondary master” in the primary master object's report category.
- “Secondary master with junction object and primary master” in the secondary master object's report category.

The order of the master objects in the report type is important. The master object listed first determines the scope of records that can be displayed in the report.

You can create custom reports based on these standard report types. In addition, you can create custom report types to customize which related objects are joined in the report.

#### See Also

- [Find Object Management Settings](https://help.salesforce.com/s/articleView?id=platform.extend_click_find_objectmgmt_parent.htm&release=264.0.0&type=5 "Salesforce lets you personalize your object model with features like custom fields, page layouts, and validation rules. Depending on which experience of Salesforce you have enabled, these customizations are located in different areas of Setup.")
- [Object Relationships Overview](https://help.salesforce.com/s/articleView?id=platform.overview_of_custom_object_relationships.htm&release=264.0.0&type=5 "Create relationships to link objects with each other, so that when your users view records, they can also see related data. For example, link a custom object called Bugs to cases to track product defects that are associated with customer cases.")
- [Considerations for Object Relationships](https://help.salesforce.com/s/articleView?id=platform.relationships_considerations.htm&release=264.0.0&type=5 "Review these considerations before creating relationships between objects.")
- [Create a Custom Object](https://help.salesforce.com/s/articleView?id=platform.dev_objectcreate_task_parent.htm&release=264.0.0&type=5 "Track and store data that’s unique to your organization. Follow different steps, depending on which Salesforce experience you’re using.")