Exam CRT-450 Topic 7 Question 185 Discussion
Actual exam question for Salesforce's CRT-450 exam
Question #: 185
Topic #: 7
Question #: 185
Topic #: 7
A developer needs to have records with specific field values in order to test a new Apex class.
What should the developer do to ensure the data is available to the test?
What should the developer do to ensure the data is available to the test?
Suggested Answer: B Vote an answer
The Test.loadData < > method inserts test records from the specified static resource .csv file and for the specified sObject type, and returns a list of the inserted sObjects1. The file contains field names and values for the test records. The first line of the file must contain the field names and subsequent lines are the field values. To learn more about static resources, see "Defining Static Resources" in the Salesforce online help2.
This method is useful for creating test data with specific field values without writing code. The other options are either incorrect or less efficient for this purpose. Anonymous Apex is a way to execute Apex code on demand in the Developer Console, but it is not a recommended way to create test data, as it is not part of the test class and may affect the org data3. SOQL is a query language that can retrieve data from the org, but it cannot create new data. Also, using SOQL to access existing data in a test class requires the @IsTest (SeeAllData=true) annotation, which is not a best practice, as it may cause test failures or unpredictable results4. Test.loadData does not support JSON files, only CSV files1. References:
* Test Class | Apex Reference Guide | Salesforce Developers
* Defining Static Resources | Salesforce Help
* Anonymous Apex | Apex Developer Guide | Salesforce Developers
* Isolation of Test Data from Organization Data in Unit Tests | Apex Developer Guide | Salesforce Developers
This method is useful for creating test data with specific field values without writing code. The other options are either incorrect or less efficient for this purpose. Anonymous Apex is a way to execute Apex code on demand in the Developer Console, but it is not a recommended way to create test data, as it is not part of the test class and may affect the org data3. SOQL is a query language that can retrieve data from the org, but it cannot create new data. Also, using SOQL to access existing data in a test class requires the @IsTest (SeeAllData=true) annotation, which is not a best practice, as it may cause test failures or unpredictable results4. Test.loadData does not support JSON files, only CSV files1. References:
* Test Class | Apex Reference Guide | Salesforce Developers
* Defining Static Resources | Salesforce Help
* Anonymous Apex | Apex Developer Guide | Salesforce Developers
* Isolation of Test Data from Organization Data in Unit Tests | Apex Developer Guide | Salesforce Developers
by Otto at Sep 25, 2024, 07:40 AM
0
0
0
10
Comments
Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.
Report Comment
Commenting
You can sign-up / login (it's free).