PDI · Question #147
A developer created a trigger on the Account object and wants to test if the trigger is properly bulklfield. The developer team decided that the trigger should be tested with 200 account records…
The correct answer is B. Use Test.loadData to populate data in your test methods. D. Create a static resource containing test data. To efficiently create 200 unique test account records with minimal code for a bulkified trigger test, store the data in a static resource and then load it into the test method using Test.loadData.
Question
A developer created a trigger on the Account object and wants to test if the trigger is properly bulklfield. The developer team decided that the trigger should be tested with 200 account records with unique names. What two things should be done to create the test data within the unit test with the least amount of code? Choose 2 answers
Options
- AUse the @isTest(isParallel=true) annotation in the test class.
- BUse Test.loadData to populate data in your test methods.
- CUse the @isTest(seeAllData=true) annotation in the test class.
- DCreate a static resource containing test data.
How the community answered
(59 responses)- A10% (6)
- B83% (49)
- C7% (4)
Why each option
To efficiently create 200 unique test account records with minimal code for a bulkified trigger test, store the data in a static resource and then load it into the test method using `Test.loadData`.
`@isTest(isParallel=true)` enables test methods to run concurrently but does not reduce the code needed for creating test data itself.
`Test.loadData` is an efficient and recommended method to insert a large volume of test data into test methods from a static resource, significantly reducing code within the test class.
`@isTest(seeAllData=true)` provides access to existing organization data, which is generally discouraged for isolated unit tests and does not help in creating a new, specific set of bulk test data.
Creating a static resource to contain 200 unique account records (e.g., in a CSV file) allows for external management of test data, minimizing the amount of Apex code required to generate these records in the unit test.
Concept tested: Efficient bulk test data creation
Source: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_testing_data_methods.htm#apex_testing_data_methods_loaddata
Topics
Community Discussion
No community discussion yet for this question.