Salesforce Platform Developer I (legacy) — Question 161
A developer has identified a method in an Apex class that performs resource intensive actions in memory by iterating over the result set of a SOQL statement on the account. The method also performs a DML statement to save the changes to the database.
Which two techniques should the developer implement as a best practice to ensure transaction control and avoid exceeding governor limits? (Choose two.)
Answer options
- A. Use the @ReadOnly annotation to bypass the number of rows returned by a SOQL.
- B. Use partial DML statements to ensure only valid data is committed.
- C. Use the System.Limit class to monitor the current CPU governor limit consumption.
- D. Use the Database.Savepoint method to enforce database integrity.
Correct answer: C, D
Explanation
The correct answers are C and D because monitoring the CPU governor limit with System.Limit helps the developer stay within resource limits, while using Database.Savepoint ensures that changes can be rolled back if necessary, maintaining data integrity. Options A and B are not effective in controlling transactions or managing governor limits in this context.