Skip to main content
Henk Poell (ABNAMRO) a posé une question dans #Apex
So I set out on a mission to simplify a @testSetup in which 8 different SObjects get initialized, currently using APEX inserts. Surely, the 'Advanced APEX' book pointed out the Test.loadData() method that would help here by using an undocumented feature... That one is well-known actually: you can set the Id fields and lookups to it with small integers. Seems genious! The results are in:

1) Triggers don't seem to fire during load, try a single debug statement on before insert. That means you create a different a different setup as triggers may do much-needed work.

2) The order of columns seems to matter, my second csv static resourse needed the Id column *after* the lookup column to the first one to proceed to the next error.

3) Dependent picklists with a default may throw errors. No indication which of the 50 picklists is the culprit. Same errors not there when inserting with exactly the same fields using APEX. May have to do with not running triggers.

4) No documentation about setting Id's and references to it - yeah that's a reason to include them but that defeats the purpose.

My conclusion is that using Test.loadData() is asking for trouble if you want to use it for setting up anything more complex. The method is probably fine for filling a single SObject, like a long list of countries though.

Any thoughts? Did I miss something?
0/9000