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
Bernard FarrellBernard Farrell 

'Best' way to define a many to many relationship between two custom object types?

I have an application where I want to tie Worker objects to Address objects. The same address can be used by many workers and each worker can be located at many addresses.

I looked in the development area and saw a reference to a junction object. Is this just a simple object containing two Lookup fields or is there someway to automatically create a many-to-many relationship?

Would it work to simply have the Worker object contain a lookup field for the Address object and the Address object have a Lookup(Worker) field?
Bernard FarrellBernard Farrell
After posting this question I came across this IdeaExchange proposal to support many to many relationships.

If anyone has other suggestions for resolving this, that provides useable reports and a UI I'd be most interested in hearing them.
RickyGRickyG
Yes, the way to go is to use a junction object, which would contain at least a lookup to each of the multiple sides of the relationship.

Hope this helps.
Bernard FarrellBernard Farrell
OK this is apparently the way to do it in Salesforce.

How does this work with report creation? If I have a main object that has junctions to two other object types, I end up with five objects:
  1. Primary Object A.
  2. Secondary Object B.
  3. Secondary Object C.
  4. Join object for many-to-many between Object A and Object B.
  5. Join object for m-m between Object A and Object C.
When I attempt to create a report, there's a limit of two objects. Is there a 'better' way so that I can write a report for Object A that also lists some details for the two secondary objects it links with?
RickyGRickyG
Bernard -

Check out Custom Report Types in the on-line help.  They are just what you need, I believe.
 
blntblnt

Rick,

 

I have an object A wich is has a lookup field to an object B and C but I am unable to get a custom report to show me anything more than a list the names of related object B and C.

 

How can I get a list of related B and C objects with other fields from B and C?

 

Thanks,

 

 

Bao-Long