PDI · Question #20
Given the following Anonymous Block: Which one do you like? What should a developer consider for an environment that has over 10,000 Case records?
The correct answer is A. The transaction will fail due to exceeding the governor limit. When processing over 10,000 Case records in an anonymous block, the transaction will likely fail due to exceeding Salesforce governor limits, as LimitExceptions are uncatchable and cause transaction rollback.
Question
Given the following Anonymous Block:
Which one do you like? What should a developer consider for an environment that has over 10,000 Case records?
Exhibit
Options
- AThe transaction will fail due to exceeding the governor limit.
- BThe try/catch block will handle any DML exceptions thrown.
- CThe transaction will succeed and changes will be committed.
- DThe try/catch block will handle exceptions thrown by governor limits.
How the community answered
(38 responses)- A76% (29)
- B16% (6)
- C3% (1)
- D5% (2)
Why each option
When processing over 10,000 Case records in an anonymous block, the transaction will likely fail due to exceeding Salesforce governor limits, as `LimitException`s are uncatchable and cause transaction rollback.
Salesforce governor limits impose restrictions, such as a DML row limit of 10,000 records per transaction. Processing more than 10,000 Case records in a single anonymous block transaction will exceed this limit, causing the transaction to fail and roll back.
While try/catch blocks can handle many types of Apex exceptions, they specifically cannot catch `LimitException` or `System.LimitException` which are thrown when governor limits are exceeded.
A transaction attempting to modify or query over 10,000 records without proper batching or limits is almost guaranteed to hit governor limits and therefore will not succeed and commit changes.
Try/catch blocks are ineffective against governor limit exceptions; these exceptions are uncatchable and lead to the immediate termination and rollback of the entire transaction.
Concept tested: Apex governor limits (DML, large data volumes)
Source: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_gov_limits.htm
Topics
Community Discussion
No community discussion yet for this question.
