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

Loading Parent and Child records at the same time

I am currently trying to load records into an object, followed by detail records into a child object (master-detail relationship). I will be using the data loader in batch mode to achieve this. The key difficulty with this is that in order to load the child record, you need the ID of the parent record, but of course you don't have this from the outset, so I wondered if anyone has done this before, and how you achieved it.


I will be experimenting this afternoon, but what I figure WON'T work is to create an insert trigger for the detail object so that it looks up and adds the parent ID on the BEFORE UPDATE trigger. 


My second idea, which I believe would work, is to load all child records against a dummy parent, but use a trigger to look up and assign the real parent.


My third idea is to load the parents, then extract all the IDs, then do a join with the child records outside of Salesforce before loading. This is the most foolproof, but involves the greatest complexity, so I'm trying to avoid.


Any comments, ideas or feedback on the above would be gratefully received. Thanks!


Unexpectedly (by me, anyway), it IS possible to assign the parent on the BEFORE trigger. The parent ID is a required field, but even though it's missing on the data load file, there is no error because the trigger is adding this on before the insert. This appears to be the best way forward, but comments still welcome.


Hey, i would prepfer second method. Create a trigger on your child object which looks up for the parent record before insert  is happened.