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
Daniel HodousDaniel Hodous 

Is it possible to create a many to many relationship without Junction tables, example: link two data tables by their record ID so their is no third party table creating the relationship?

So if I have two tables lets say Person table & Address table and I want them to be many to many, and I don't want to use a Junction table to create that relationship, is it possible to somehow link them via the record ID in some other method that wouldn't involve junction tables.  With over 100 data tables that have 1,000's of records with the possibilities of infinte many to many relationships needed I just want to see if its possible in anyway to create those many to many relationships without creating a junction table every time.  Thanks!
Vladimir SaturaVladimir Satura
If you want 'real' relationships and 'real' many to many you have to have a junction table.

There are some ways how to get away without additional table, but usually they are not the proper way to do stuff and are very limited:
  • If you know many to many is only limited, you can create a lookup for each item related. (How many addresses a person is going to have? 5? You can have 5 lookups on Person Table to Address Table - Address1, Address2, Address3, ... Same with addresses, how many people are going to have same address? etc...)
  • You can create a text field on Person object name Addresses IDs, and you will store list of Address Ids in it: "001i000001AWbWugta;001i000001AWbWugtb;001i000001AWbWugtc;001i000001AWbWugtd;001i000001AWbWugte;". You can then use them in apex - parse the list, get Ids, do query to get addresses records or to do SOQL with wildcard search to see if the ID is in the list (This can also be long text area to be able to store more IDs, but you won't be able to index the field, do wildcard search, etc...)
Dylan PeralasDylan Peralas
I would also like to chime in, that at some point if you went that 'alternate' route, you are going to hit severe system limitations and acheive stack overflow errors as data table strings can only exist to a finite length, and that text field has the potential for infinite density. I would strongly advise against it.