A developer is inserting, updating, and deleting multiple lists of records in a single transaction and wants to ensure that any error prevents all execution.
How should the developer implement error exception handling in their code to handle this?
A.
Use Database methods to obtain lists of Database.SaveResults.
B.
Use a try-catch statement and handle DML cleanup in the catch statement,
C.
Use Database.setSavepoint {} and Database.rollBack with a try-catch statement.
D.
Use a try-catch and use sObject.addError() on any failures.
Using Database.setSavepoint() and Database.rollback() within a try-catch statement is the recommended approach for handling transactions that involve multiple DML operations. This allows the developer to roll back all changes if an error occurs, ensuring that partial changes are not committed to the database.
[References: Apex Developer Guide - Savepoint and Transaction Control]
Contribute your Thoughts:
Chosen Answer:
This is a voting comment (?). You can switch to a simple comment. It is better to Upvote an existing comment if you don't have anything to add.
Submit