To create a many-to-many relationship: | “Customize Application” |
- 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 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.
- Creating the junction object.
- Creating the two master-detail relationships.
- Customizing the related lists on the page layouts of the two master objects.
- Customizing reports to maximize the effectiveness of the many-to-many relationship.
Creating the Junction Object
- From Setup, click Create | Objects.
- Click New Custom Object.
- 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, it is recommended that you use the auto-number data type.
- Do not launch the custom tab wizard before clicking Save. Junction objects do not need a tab.
Creating the Two Master-Detail Relationships
- Verify that the two objects you want to relate to each other already exist. For example, you may want to relate the standard case object to a custom bug object.
- On the junction object, create the first master-detail relationship field. In the custom field wizard:
- Choose Master-Detail Relationship as the field type.
- 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 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 do not have a visible Owner field, this is only relevant if you later delete both master-detail relationships on your junction object.
- Division: If your organization uses divisions to segment data, the junction object records inherit their division from their associated primary master record. Similar to the record ownership, this is only relevant if you later delete both master-detail relationships.
- 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 in order to create, edit, or delete its associated detail records.
- For the Related List Label that will display on the page layout of the master object, do not accept the default. Change this to use the name of the other master object in your many-to-many relationship. For example, change this to Bugs so users will see a Bugs related list on the case detail page.
- On the junction object, create the second master-detail relationship. In the custom field wizard:
- Choose Master-Detail Relationship as the field type.
- 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.
- 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 in order to create, edit, or delete its associated detail records.
- For the Related List Label that will display on the page layout of the master object, do not accept the default. Change this to use the name of the other master object in your many-to-many relationship. For example, change this to Cases so users will see a Cases related list on the bug detail page.
Customizing 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 might change the BugCaseAssociations related list toCases 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.
- Edit the page layout of each master object that is related to the junction object. For example, to modify the BugCaseAssociations related list for case records, edit the page layout for cases from Setup by clicking Customize | Cases | Page Layouts.
- 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.
- 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 popup window. In the related list itself, only fields from the junction object are prefixed with the object name; fields from the other master object are not.
Customizing Reports for Many-to-Many Relationships
- “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.
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.
No comments:
Post a Comment