Create many to many relationship using Junction object
Junction Object or Many to Many Relationship in SFDC
There is no out of box relationship present in SFDC i.e. Many to Many in nature, So to have a many to many relationship in SFDC a JUNCTION OBJECT is required.
A junction object joins the two objects with two master detail relationship. Junction object is always on the detail side of the object.
A1__c M : 1 Junction (J__c) 1 : M A2__c
This way junction object creates Many to Many relationship between A1__c and A2__c. (DEV 401 Question)
One example of many to many relationship among standard objects is Case and Solution. One case can have many solution attached to it and one solution can be used in resolving many cases.
What is a Junction?
Object used for creating many-to-many(m-m) relationship between 2 objects. Junction object will have 2 master-detail fields.
Example: To create m-m relationship between object A1__c and A2__c, create a junction object J__c with Master detail field corresponding to A1__c and A2__c.
Few important points (Interview Questions of salesforce ):
- One Object can have only two Master-Detail relationships.
- If we delete record A (First Master detail relationship is always primary) – then child record c will be deleted.
- If we delete record B then in this case also child record C will be deleted.
- If we delete record c then only C will be deleted , master record will not be deleted.