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
admintrmpadmintrmp 

Test.loadData() - How useful is it?

Our data structure runs on a quite a deep hierarchy. In order to have many of Object B, we must have at least a single Object A, and so forth.

 

How can we use Test.loadData() to set a list of records like this? Or is this not possible?

Am I right in thinking that this method can only set data to a single object and cannot populate relationships?

 

I would like to be able to something like:

 

ChildTestData.csv

"ID","Name","ParentID"

"1","Jim","2"

"2","John", "2"

"3","Jake","3"

 

 

ParentTestData.csv


"ID", "Name"

"1", "Kim"

"2", "Karen"

"3", "Kelly"

 

 

This would result in Jim and John to children of Karen, while Jake is a child of Kelly.

 

 

Also, does this method use up any DML statements?

 

Thanks

Philip FPhilip F

Hi there.

 

I haven't seen any official documentation on whether this Method uses up DML statements, but it seems like it does.  To evalutate this, I ran a quick test.  I tried calling the Test.loadData method using the same file into two different lists and each call increased the number of DML statements that listed in the "Number of DML statements" value for the Debug Log Profiler.  Removing a call to loadData decreased the number of DML statements.

 

As to your main question, the documentation has an official statement on how to handle what you'd like to do: Official Help Page.  Personally, I opted to create the links (populate the parent ID in the child) manually in code to avoid adding unnecessary fields to the objects.

 

Cheers,

-Philip