1
votes

I have a question regarding the rollback mechanism in CRM 2011. I know that a synchronous plugin will rollback any changes it has performed if an error is thrown. But what if this plugin triggers another plugin during it's execution.

Consider the following plugins:

  1. Plugin A: Triggers on pre-UPDATE of Task entity
  2. Plugin B: Triggers on pre-UPDATE of Case(incident) entity

Scenario would be like this:

  1. I update a case and Plugin B get's triggered.
  2. Fields in the case are modified
  3. One of the Tasks associated with the case is also updated with some information.
    • Plugin A is triggered
    • Fields related to the task are modified
  4. Some other operations on the case record
  5. Plugin B throws exception

My question is, would the operations performed in Plugin A get rolled back as well?

Thanks and Regards, Paul

1

1 Answers

3
votes

As long as the plugins are registered in the transaction (before or after, but still in), everything will get rolled back. If a plugin is registered for the Pre-Validation stage, it will not get rolled back.

This also assumes that you're retrieving the IOrganziationService from the PluginContext as well.

This is what happens on the server:

  1. A request to update an entity comes in, are we currently in a transaction via the context? If not create a new Database Transaction and store it in the Plugin Context.
  2. Request is made to update a different entity, transaction is passed to the new plugin's context, and step 1 is repeated for new plugin execution.