Plat-Dev-201 practice question 22 of 30

What is the result of the following code snippet? public word doWork(Account acct) { for (Integer i = 0; i

Full set: 204 questions
Answer options
A: Accounts are inserted.
B: Account is inserted.
C: 200 Accounts are inserted.
D: 201 Accounts are inserted.
Correct Answer:
N
Explanation

The provided Apex code will fail and no records will be committed to the database. The code attempts to perform a DML insert statement inside a for loop that iterates 201 times. Apex has a governor limit of 150 DML statements per transaction. On the 151st iteration, the code will throw a System.LimitException: Too many DML statements: 151. This exception causes the entire transaction to roll back, meaning any accounts inserted in the first 150 iterations are not saved. Furthermore, attempting to insert the exact same sObject instance more than once in a transaction would cause a DmlException after the first successful insert.

Why Incorrect

A. This is incorrect. The transaction fails due to governor limits, and no accounts are ultimately inserted.
B. This is incorrect. The code attempts to insert the account multiple times before the transaction fails and rolls back.
C. This is incorrect. The code attempts 201 insertions, not 200, and the transaction fails before completion.
D. This is incorrect. While the loop iterates 201 times, the transaction fails due to exceeding the DML governor limit.

References

1. Salesforce Developer Documentation, Apex Governor Limits. The "Execution Governors and Limits" chart explicitly states the limit for "Total number of DML statements issued" is 150 for synchronous Apex.

2. Salesforce Developer Documentation, Apex Developer Guide, "Triggers and Order of Execution". This document explains that if a limit is exceeded, any DML operations are rolled back. Section: "Transaction Control".

3. Salesforce Developer Documentation, Apex Developer Guide, "Exception Handling". Describes how unhandled exceptions, such as LimitException, halt execution and roll back the transaction.

Scroll to Top