Salesforce: Junction Object as Parent Object
September 14, 2012 /
Posted in Salesforce Corner
In Salesforce, a junction object cannot be the parent in a master-detail relationship.
Use case: A company that sells water heater will install their product for different owners in different locations. We will use the Account object to represent the Owner. Location object is like a city/state. One Account can have multiple Location and One Location can have multiple Owners. To achieve the many-to-many relationship, we create Account Location as the junction object. If you create another object called “Installation” and park this object as a child under Account Location using Master-Details relationship, Salesforce will not allow this. Below is the behaviour you will encounter:
Behavior #1:
- Account object is already exist in Salesforce.
- Create a new custom object named Location.
- Create a new custom object named Account Location (this will be the junction object).
- Create 2 master-detail relationship on Account Location object link to Account and Location.
- Create a new custom object named Installation.
- Create a master-detail relationship on Installation link to Account Location. The Account Location object will not be listed as an option.
Behavior #2:
- Create a new custom object named Installation.
- Create a new custom object named Account Location.
- Create a master-detail relationship (Account Location) in Installation object.
- Account object is already exist in Salesforce.
- Create a new custom object named Location.
- Create 2 master-detail relationship on Account Location object link to Account and Location. When you trying to create the second master-detail relationship in Account Location, you will see the following:
To overcome this, you can use normal Lookup relationship between Account Location and Installation object.