2

My understanding is that test.dataload() will upload the test data to Salesforce temporarily during the execution time of the test method. However, I am curious if triggers and Process Builders applied to the desired object will behave as expected during insert, update, and delete, Or will they be ignored?

coming from a web developer background, a mock JSON file is just sitting on the local machine and does not get uploaded to the database. Any manipulations to the object will just be directly on the local machine. That's where my confusion is coming from. I'm hoping that the Triggers and Process Builders will not start but I have a feeling that they will.

1 Answer 1

5

Yes. Triggers, process builders, workflow rules, validations etc., will be executed when you use Test.loadData method in test class. I was hoping they wouldn't just like you, but they are being executed unfortunately.

In my experience the benefits of using Test.loadData are:

  1. Bulk testing. You could export data sets from your full copy sandbox or production and run test methods on that data to validate functionality to cover more scenario/ code blocks. Test execution time is much lower this way compared to creating large volume of data within code.
  2. Easily change data at a later point in time similar to test factory. Suppose there is a need for new validation rules on requiring certain fields, you could just update the csv file in static resource instead updating all the test methods. I still prefer test factory for this purpose.
  3. Workaround for populating custom values for system fields. Ex: ClosedDate on Case. At the moment there is no way to set ClosedDate in the past in test classes (You could set CreatedDate, but not ClosedDate). You could just insert a few cases with Status Closed and ClosedDate in the past.

Maintaining the static resources may be a chore depending on how you use it.

You must log in to answer this question.

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