Exam PDII Topic 2 Question 89 Discussion
Actual exam question for Salesforce's PDII exam
Question #: 89
Topic #: 2
Question #: 89
Topic #: 2
A developer created the following test method:
Java
@isTest(SeeAllData= true)
public static void testDeleteTrigger(){
Account testAccount = new Account(name = 'Test1');
insert testAccount;
List<Account> testAccounts = [SELECT Id, Name from Account WHERE Name like 'Test%']; System.assert(testAccounts.size() > 0); delete testAccounts; testAccounts = [SELECT Id, Name from Account WHERE Name like 'Test%']; System.assert(testAccounts.size() == 0);
}
The developer org has five accounts where the name starts with "Test". The developer executes this test in the Developer Console.
After the test code runs, which statement is true?
Java
@isTest(SeeAllData= true)
public static void testDeleteTrigger(){
Account testAccount = new Account(name = 'Test1');
insert testAccount;
List<Account> testAccounts = [SELECT Id, Name from Account WHERE Name like 'Test%']; System.assert(testAccounts.size() > 0); delete testAccounts; testAccounts = [SELECT Id, Name from Account WHERE Name like 'Test%']; System.assert(testAccounts.size() == 0);
}
The developer org has five accounts where the name starts with "Test". The developer executes this test in the Developer Console.
After the test code runs, which statement is true?
Suggested Answer: A Vote an answer
Every Apex test execution is treated as a temporary transaction. One of the most critical aspects of this execution is that any changes made to the database-including the insertion, modification, or deletion of records-are automatically rolled back at the end of the test run. This mechanism ensures that unit tests do not leave behind "garbage" data or alter the state of the organization's actual business data, maintaining a consistent environment for development and production.1234 In this specific scenario, the @isTest(SeeAllData=true) annotation is used, which allows the test method to view existing data in the organization. Bec5ause the org already contains five accounts starting with "Test," the test method sees them. When the test code inserts a new 6account named "Test1," the count within that specific transaction becomes six. The subsequent code queries for these six accounts an7d del8etes them.
While the test is running, the deletion is successful, which is why the assertion checking for zero accounts passes.
However, once the test finishes, the entire transaction is rolled back. The rollback effectively "undoes" the deletion of the original five accounts and the creation of the one new account. Consequently, the organization returns to its exact state from before the test was initiated. The five original accounts remain in the database as if the test never occurred, making option A the correct answer.
While the test is running, the deletion is successful, which is why the assertion checking for zero accounts passes.
However, once the test finishes, the entire transaction is rolled back. The rollback effectively "undoes" the deletion of the original five accounts and the creation of the one new account. Consequently, the organization returns to its exact state from before the test was initiated. The five original accounts remain in the database as if the test never occurred, making option A the correct answer.
by Wanda at May 21, 2026, 08:54 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).