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
avimeiravimeir 

Many-to-many relationship

Hi All

 

I am new to Force.com, trying to figure out a way to create a many-to-many relationship of objects.

 

I have two custom objects: Rooms and Reservations. A reservation can have zero or more rooms assigned to it, and a room can be assigned to zero or more reservations.

 

I tried using Master-Detail but it requires a single assignment on one of the objects, instead - I want to have lists on both objects, that can be empty or have more than 1 items.

 

Thanksq

Best Answer chosen by Admin (Salesforce Developers) 
Madhan Raja MMadhan Raja M

You need to create a third object called Junction object to achieve Many to Many relationship. Rooms and Reservations objects will be the master for Junction object.

 

Creating a Many-to-Many Relationship: https://ap1.salesforce.com/help/doc/en/relationships_manytomany.htm

 

Madhan Raja M

All Answers

TrimbleAgTrimbleAg

Just use the standard relationship, also, I would say to explore the new schema builder.

 

PB

Madhan Raja MMadhan Raja M

You need to create a third object called Junction object to achieve Many to Many relationship. Rooms and Reservations objects will be the master for Junction object.

 

Creating a Many-to-Many Relationship: https://ap1.salesforce.com/help/doc/en/relationships_manytomany.htm

 

Madhan Raja M

This was selected as the best answer
avimeiravimeir

Thanks!

cruttleycruttley

And some followup advice.

- Naming

  - Room

  - Reservation

  - Room Reservation (this should be the name of many to many resolution object).

 

Master detail relationships

- between Room and Room Reservation...this gets interesting. If someone deletes a Room (rare), would you want all the Room Reservations to cascade delete? Probably not. So I would not advise a Master Detail relationship

- between Reservation and Room Reservation ...far more common for someone to delete a reservation. But once again, I assume that you wouldnt actually want to delete a Reservation (probably change its status instead). So I would not advise a Master Detail relationship for this scenario either.

avimeiravimeir

Thanks for the great advice!