Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Salesforce by (11.9k points)
edited by
I need to load data into two objects. I am able to load data into one object using the data loader. The second object has a master-details relationship with the first object so I need to have the unique record id of the records of first object in the CSV file. How can I add those record id's to my CSV file?

1 Answer

0 votes
by (32.1k points)
edited by

Download the "master" records after primary upload and perform some mapping related to (Name -> Id). In Excel, this could be accomplished with VLOOKUP. Once you have formed a new list of "detail" objects, there should be no difficulty uploading them. The mapping "ID->uploaded records" is also accessible in the success log file created by Apex Data Loader.

But the better way is to say loudly "screw the Salesforce ID, I don't need no stinking ID" :) Think if your "master" has some unique field. It can even be the "ID" from your existing system from which you import to Salesforce. Create this field in Salesforce (if you didn't do it already) and mark it as "External ID". Afterwards, you will be able to use this external ID instead of normal Salesforce ID as a way to make the link between source and target. In pseudocode:

with normal Salesforce ID, you must

INSERT INTO detail_object (Name, SomeValue, master_ID) VALUES ("foo", "bar", [some valid salesforce id])

With external IDs, you can have it easy and tell salesforce to do all the heavy lifting

INSERT INTO detail_object (Name, SomeValue, master_ID) VALUES ("foo", "bar", (SELECT Id from master_object where some_field_marked_as_external_id = "123")

Check out the Data Loader user guide for a quick start and play with external ids if you can (in the free developer edition maybe?). It's easier to use than to describe it.

Look at this Salesforce Course provided by Intellipaat!

Browse Categories

...