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
SFDC_BigDogSFDC_BigDog 

Many to Many relationship

I have a requirement of creating a many to many relationship between two objects Owner and contractor. My idea is to firstly create the juntion object and establish Master Detail Relationships on the junction object.

Later If I load the data(owner and contractor) through dataloader will the many to many realationship be in effect immediately or do i have to check for each and every record?
sandeep sankhlasandeep sankhla
HI SFDC_Penna,

Once you load the data in junction object , relationship will be in effect Immediately...

P.S. If my answer helps you to solve your problem please mark it as best answer. It will help other to find best answer.

Thanks,
Sandeep
Salesforce Certified Developer 
SFDC_BigDogSFDC_BigDog
Hey Sandeep,

But my requirement is I don't have the junction object data. I have the Owner and Contractor data. I have to upload the data of the Owner and COntractor. How will I do that? 
sandeep sankhlasandeep sankhla
Hi SFDC,

Then you can simply upload the data for Owner and Contractor ...onc eyou will upload the data then user will be able to create many to many relationship from junction object...

Supopose you have uplaoded the data

Example:

Owner1. Owner2, owner3 and Contractor1, Contractor2 , contractor 3..

Now end user can create the junction object with these data adn stablish a many to many relationship

Junction object 1-->owner1, Contratcor1
Junction object 2--> owner1, Contarctor 2


Let me know if this is what you need..I think you dont need to create the junction object record because you dont have data, which owner should be mapped with which contractor..

Please confirm

P.S. If my answer helps you to solve your problem please mark it as best answer. It will help other to find best answer.

Thanks,
Sandeep
Salesforce Certified Developer 
sandeep sankhlasandeep sankhla
Hi SFDC,

I think you need tio simply upload the data for these 2 objects and relationship you have already created in org...so after uploading the data user will be able to map the owners with contratcors...

Let me know if you need any help in uploading the data..

Thanks,
Sandeep
SFDC_BigDogSFDC_BigDog
Hey Sandeep,

Thanks for the reply. But my requirement is I have to show the many to many relationship. In this case I don't have an end user. So I need to upload the owner and contractor records. Then I should be able to relate them using many to many relationship i.e. using juntion object. 

So.

1)I will upload owner records
2)I will upload contractor records
3)  Now how can I extablish realtionship between them? The relationship is many to many. 
sandeep sankhlasandeep sankhla
Hi SFDC,

I think you need tio simply upload the data for these 2 objects and relationship you have already created in org...so after uploading the data user will be able to map the owners with contratcors...

Let me know if you need any help in uploading the data..

Thanks,
Sandeep
sandeep sankhlasandeep sankhla
Hi SFDC,

I think I got your point..you need to basically relate all owners with all contarctors right ??

Give me sometime , I will provide you the solution to you...

Thanks,
Sandeep
sandeep sankhlasandeep sankhla
Hi SFDC,

As per my understanding if you have 5 owners and 5 contractors then it should create 25 junction records by relating each owner with each contractor..Please confirm this..

Thanks,
Sandeep
SFDC_BigDogSFDC_BigDog

Hey Sandeep,

In my case I have csv files of owners and contractors. Now I have created objects in salesforce i.e. owner , contractor and OwnerContractorAssociation(junction object). I guess now you can understand my requirement. While uploading the data into owner and contractor, will I be able to see the records automatically in the junction object or do I have to map after uploading the data.

 

 

Anupam RastogiAnupam Rastogi
Hi Penna,

After populating data in the Owner and Contractor objects you need to do the following to establish the many to many relationship - 

1. Retrieve the Salesforce Ids for the Owner and the Contractor objects records uploaded by you using a Query
2. Place the Ids for both the objects in a single sheet. Make sure that for every related Owner and Contractor there is a single row having their respective Ids in separate columns
3. Use this sheet to upload data into the Junction Object.

So basically what we did above is - 
    As the Junction object already must be having two Master Detail relationships with the Owner and Contractor objects, when we populate it with the Ids the relationship is formed.

So for example if you have the following data - 

Owners                                  Contractors
Owner 1                                  Contractor A
Owner 2                                  Contractor B
Owner 3                                  Contractor C

After populating their data you query and get their Ids and arrange them in another sheet to be used for populating Junction object - 

Owner Id                                 Contractor Id
Owner 1 ID                               Contractor A ID
Owner 1 ID                               Contractor C ID
Owner 2 ID                               Contractor B ID
Owner 2 ID                               Contractor C ID
Owner 3 ID                               Contractor A ID

So this will create the 5 records in the Junction object and the following relations - 

Owner 1 related to Contractor A and C
Owner 2 related to Contractor B and C
Owner 3 related to Contractor A

Thanks
AR
sandeep sankhlasandeep sankhla
Hi SFDC,

You can simply insert all Owners adn then contractor in your org..then we can simply execute a batch code only for a time to create many to many relationship bewteen them...

which menas if you have 10 owners adn 10 contractors then it should create 10*10 = 100 junction record then all it will be many to many relationship...without code it will be too muhc manual work and time consuming ..

Please confirm and let me know your thoughts if you need code to create these relationship instead of excel..

Thanks,
Sandeep
SFDC_BigDogSFDC_BigDog
Hey Sandeep,

I have inserted all the owner and the contractor records. Now how to execute a batch code. Could you provide me any example or any reference link so that I can learn. This could be very helpful.

Thank you.
 
SFDC_BigDogSFDC_BigDog
Hey Anupam,

I am right following the process that is mentioned by you as I don't have any common field. Now when we have bulk records, is this the only way that we can achieve this ?

Thank you.
Anupam RastogiAnupam Rastogi
Hi Penna,

Does the data for Owner and Contractor contains at least the row Ids of the source system from where you got this data?

And does those row Ids are related within the data set?

Thanks
AR
Anupam RastogiAnupam Rastogi
Hi Penna,

I assume that the identifier column must be unique for all the Account records. But there has to be a relation between the related Owner and Contractor Account records.

If that is not the case then what exact requirement did you get from the client? Is it that the client is expecting all Owners to be related to all Contractors?

Because you are trying to populate a many to many relation in Salesforce, you need to have relationship between the records.

Thanks
AR
SFDC_BigDogSFDC_BigDog
Hey Anupam,
I was asked to show in this manner.

When they click on any owner they should be able to see all related contractors and vice versa.

Thank you.
Anupam RastogiAnupam Rastogi
Okay, in that case, ask them a question, "what you mean by related Contractor records?"

See, either you are missing something from the data that is given to you, Or the requirement is not well defined. In any case, there has to be clear understanding about how Owners are related to Contractors and vice-versa.

Is it that any Owner needs to be related to all Contractors and vice-versa?

AR
sandeep sankhlasandeep sankhla
Hi SFDC,

This is what my initial question from starting..there should be some relation to relate them ..You can confirm from your clien then we can relate and create them..You should know which owner is related to whihc contratcor..

Thanks,
Sandeep
SFDC_BigDogSFDC_BigDog
Yeah.. via junction object. But I don't see any common field so that I can relate. Just the names of owners and contractors have resemblence. 
For eg1: Owner name: Penn State- Belfor USa, USPS- Belfor USA
              COntractor Name: Belfor USA

Just by observing these we have to relate them. TIll now for 50 records I have done  manually. 
 
sandeep sankhlasandeep sankhla
Hi SFDC,

It means after - Contractor Name is there...

Owner Name will contain the Contractor name just after -.

If you have less owner records and then from excel itself you can filter and relate them else we need to do it by code..

Can you tell how many owners and Contartcors records are there to insert ?



Thanks,
Sandeep
SFDC_BigDogSFDC_BigDog
Hi Sandeeep,

We need to Insert around 3600 records.
Anupam RastogiAnupam Rastogi
Hi Penna,

I do not think this is a good approach to relate records. There can be several contractors in an area which can provide support to a particular Account. And not always the names will refer them.

More importantly, data is the most crucial element of any application. And if that goes wrong then it can be a big problem for the users. So I would again suggest that you talk to the client for identification of the relationship.

Just do not continue guessing for the sake for completing this job at hand.

Thanks
AR
SFDC_BigDogSFDC_BigDog
Hi Anupam,

Thanks for the suggestion. I will talk to the client and identify the relationship. Till now I was working on the sample data of 50 records. Now when it comes to the point of bulk records, I guess I should follow your advise. 

Thanks again Anupam and Sandeep. 
sandeep sankhlasandeep sankhla
Hi SFDC,

I am 200% agree with Anupam, if you are not confirm and this is only your assumption then it is not good to implement it...if you are sure then only we can go ahead with this..

Better you confirm from your client then we can proceed..

Thanks,
Sandeep
Salesforce TechieSalesforce Techie
refer - https://www.youtube.com/watch?v=4D5QQTKISP8