Using Apex Data Loader to load records into object with master details relationship

浪子不回头ぞ 提交于 2019-12-06 02:52:19

You could download the "master" records after initial upload and perform some mapping similar to (Name -> Id). In Excel this could be achieved with VLOOKUP. Once you have generated new list of "detail" objects, there should be no problem uploading them. The mapping "ID->uploaded records" is also available 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 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.

If you are using the Apex Data loader then you will have to do 3 things:

1: insert the master record(s). this will give them IDs

2: export those master records again including their IDs, and integrate that into your details data. A VLOOKUP is most useful for that sort of thing.

Or if there is only one master record, even easier, just copy the ID out of the URL and add it in on every detail record in your spreadsheet.

3: then insert the detail records with the master IDs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!