We have some custom object that has lookups to itself. Those objects used for some configs and there are quite a lot of them. Would be nice to create and load them from static resource for tests as well as import to another orgs.

I tried to use this approach Test.loadData() - undocumented (but useful) behavior loading relationships but looks like it's not possible to insert objects with lookups to itself.

That topic is quite outdated maybe there is some new solution?

  • You can specify ids, right? Just load the parents first, then the children?
    – Adrian Larson
    Apr 27, 2017 at 16:15
  • Thanks @AdrianLarson! This approach works in test classes. Will try External ID for data loader Apr 27, 2017 at 18:03

1 Answer 1


Just specify the Id values, then load the parent record(s) first, followed by any child records. A simple example would be to use the Account object and its ParentId field.

Static Resource 1:

Id                 ParentId

Static Resource 2:

Id                 ParentId
001000000000001    001000000000000
001000000000002    001000000000000
001000000000003    001000000000000

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .