Unit Of Work
Introduction
The Unit of Work class implements the common enterprise pattern intended to optimize the database access for each transaction. The main benefits are:
- Reduction of the number of DML operations executed against the database. This is important because the Salesforce platform limits regarding DML operations.
- Autoresolving parent-child relationships.
- Ensure the transaction completeness, avoiding partial DML operations.
Instead of executing DML operations (insert, update, delete) at any time that its required, all the DML operations are added to a sort of queue that is processed at the end of the transaction, reducing drastically both the number of DML operations and the time spent in database operations.