[SalesForce] Many To many for Bulk records

I have created two custom objects (A and B)and a junction object(AB). i.e. Both A and B have Many to Many relationship. Now I need to insert 5000 records. How can I automatically populate the relation in Junction object. DO I have to write any trigger or Do I have to do Manually mapping the records?

Best Answer

The best way to achieve this is by using the data loader. I would recommend using www.dataloader.io since it is infinitely easier to use and it contains a nifty feature that will make your life easier.

Dataloader.io allows you to "lookup" related records based on a certain field, so for example:

Say you wanted to create an account via dataloader and wanted to set the OwnerId field, but you only have the email of the user you want to be set as the owner. You can configure Dataloader.io to actually do a lookup of the user id based on the email, saving you the extra step of massaging the CSV.

To be more specific to your example, I would:

  1. Make sure that Object A and Object B contain an external Id that identifies them from the old system.
  2. Do a dump of the "AB" table from the old system into a CSV. The format needs to be like this: A_OldSystemId, B_OldSystemId
  3. Use dataloader.io (Jitterbit also has this feature but I prefer dataloader.io) to load the data into the new AB Salesforce object. Make sure that you use the "Lookup" feature.

You can read about how to use the lookup feature here: https://dataloader.io/using-import-lookups

Hope this helps!

Related Topic