Our team is integrating static resources into our unit tests and were not sure about bulk testing. I have a couple of questions:

  1. Would bulk testing be done through code or through adding additional records to the Static Resources?

  2. Through static resources can you insert initial data through the and then run tests with different data sets against the previously inserted information?

I'm a new Apex developer, so these questions might be basic, but I appreciate help! Thank you for your feedback.

1 Answer 1


By bulk testing if you mean testing triggers (and corresponding handler classes) ability to process more than one record in the transaction then ...

  • You can add more rows in your static resources and insert them into the test context using Test.loadData(). There's an interesting undocumented feature (at least last I looked) to make creating relationships easier if you don't have external IDs.
  • If for some reason it doesn't make sense to use static resources, the testmethod can execute a loop to mass generate many Sobjects that you subsequently insert. See also the @TestSetup annotation where you can have a test factory that is reusable across several testmethods in a test class
  • As inserting many objects will cause triggers to run, be sure to wrap your actual testing of the classes with Test.startTest() and Test.stopTest() as the former call will reset governor limits.
  • Static resources are also a great way of mocking input CSV files or inbound emails that you might be parsing or inbound XML or REST JSON. Here, you wouldn't use Test.loadData() but instead query the static resource directly.

And the obligatory SFSE disclaimer, coverage != testing - you need to do asserts to verify your code

And the next obligatory SFSE disclaimer - avoid SeeAllData=true (in my book at almost all costs) as use of it can lead to deployment errors in your near or distant future - and such errors are very hard to identify. Mock your test data.

You must log in to answer this question.

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