function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

Many to many example

Can you please give an example to many to many relationship?




A many-to-many relationship consists of three objects: Object A and Object B are the two primary objects, and Object J is the junction that enables the many to many.

Object A  <--M/D--  Object J  --M/D--> Object B

So on Object J you need to create two Master-Detail relationships, one that points to Object A and one that points to Object B.

Hi Where we use this kind of scenario? Can you give an example scenario to this?



In salesforce many to many relationship exmples are
1)case and solution
2)campaign and lead



If this helps you, please mark this as solution so that it would be useful for others.


A many-to-many relationship uses one object to link two other objects together in limitless combinations. There are two types of these combinations, those that are unique (each pair of records can only be linked once, which actually has a limit of the product of each object involved), and those that are non-unique (each pair of records might be linked more than once).

For example, banks have many accounts, and people may have many accounts (even at the same bank), so each account a person has at a bank is a many-to-many relationship; the account itself (in database terminology) is the many-to-many object that ties the bank and the person together into a relationship, and describes their available funds, transaction history, etc.

As salesforce#1 stated, there are many examples of many-to-many relationships in

* PricebookEntry
* CampaignMember
* AccountContactRole
* Partner
* OpportunityContactRole
* CaseSolution
* OpportunityLineItem
* Asset

Each object contains two or three "primary" relationships that link those objects together, just as bank accounts link banks to people, and contains relevant information, such as the two items involved (e.g. an opportunity and each product price associated to it), and other relevant information (e.g. the quantity being sold and the discount given).