Database transaction

Depending upon the stage in which we register the plugin, the plugin will either be executed inside or outside the database transaction. Any plugin registered in stage 20 and 40 will be inside the database transaction. However, any plugin registered in the pre-validation stage, that is, 10, will be executed outside the main database transaction.

Due to this, pre-validation and pre-operation plugins differ in terms of how they perform exception handling. Mentioned here are two scenarios where instead of pre-operation, the user should use the pre-validation plugin:

The following diagram explains the relationship between Contact and Account:

And here's a diagram that helps you understand the logic to verify the subcontacts before deleting the account: