You need to sign in to do that
Don't have an account?
chriscwharris
Apex Test Data Factory master detail relationships
I have an apex trigger that runs on an object that is 3 levels down in a master detail hierarchy. I'm starting to write a test class for the trigger but need to set up the test data for the test methods. Due to the complexity of requiring a parent and grandparent in place before creating the actual records being tested I figured I would use a utility class.
Having investigated various onine resources I can see lots of examples of using a utility class to create a single type of object record and have that returned as an array which can be processed in the test class but I'm not sure how you deal with multiple levels of relationship and different object types if you need to access both the parent and grandparent records from the test methods as they are both required.
As an example:
Firstly create in Utility Class
Grandparent Record (Custom Object A)
-> Parent Record (Custom Object B)
Then the following is created in the test Class methods but needs to access both objects created above
-> Detail Record test 1 (Custom Object C) (Child of Object B which is child of Object A)
-> Detail Record test 2 (Custom Object C) (Child of Object B which is child of Object A)
-> Detail Record test 3 (Custom Object C) (Child of Object B which is child of Object A)
I may be over thinking this, any advice, examples or tips appreciated!
Having investigated various onine resources I can see lots of examples of using a utility class to create a single type of object record and have that returned as an array which can be processed in the test class but I'm not sure how you deal with multiple levels of relationship and different object types if you need to access both the parent and grandparent records from the test methods as they are both required.
As an example:
Firstly create in Utility Class
Grandparent Record (Custom Object A)
-> Parent Record (Custom Object B)
Then the following is created in the test Class methods but needs to access both objects created above
-> Detail Record test 1 (Custom Object C) (Child of Object B which is child of Object A)
-> Detail Record test 2 (Custom Object C) (Child of Object B which is child of Object A)
-> Detail Record test 3 (Custom Object C) (Child of Object B which is child of Object A)
I may be over thinking this, any advice, examples or tips appreciated!
// Create Utility Class
here's how you call this in your test class:
Or