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 questionsThe 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.
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.
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.
Keep practicing
Take the free Plat-Dev-201 practice test
Ten exam-style questions with answers and explanations, plus the exam facts and study guides.
More questions
Other Plat-Dev-201 practice questions
- Question 1Which three steps allow a custom Scalable Vector Graphic (SVG) to be included in a Lightn…
- Question 2Which two statements are true about using the @testSetup annotation in an Apex test class…
- Question 3Managers at Universal Containers want to ensure that only decommissioned containers are a…
- Question 4Universal Containers has a Visualforce page that displays a table of every Container__c b…
- Question 5A developer is alerted to an issue with a custom Apex trigger that is causing records to …
- Question 6Which two operations affect the number of times a trigger can fire? Choose 2 answers
