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:

  • As a requirement, while deleting an account, we need to make sure that the account should be deleted only if there are no subcontacts present in it.
  • If we write a plugin and register it on the PreOperation of the delete message on account, we will always get zero associated contacts. Due to this PreOperation will not suffice the requirement. However, if we register the same code as a PreValidation plugin, it will work correctly.

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:

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset