Pre-validation, Pre-operation and Post-operation on Synchronous and Asynchronous plugins in CRM 2011

Hi Everyone, I decide to write something about this topic since I don’t really get it. The Pre-validation stage will allow your plugin to run outside the SQL transaction, that means that the after the form is submitted, but before the record is created is where the plugin runs, the purpose should be to check a condition to allow the record creation.

The Pre-operation stage happens after the validation and before the values are saved into the database, at this point we should be sure that the record can be created, but we are still in time to change some bit and pieces.The Post-Operation operation plugin runs after the values have been inserted/changed in the database. A lot of fancy words, but the problem is that is not as straightforward as it seems.

Basically you are aware that if you use the first two steps the record is not there, so is pointless to look for it in the context (I like to use an early bound approach so I can use Linq queries to filter the data), but when you try to query an entity on a post operation plugin you expect (or at least I was expecting) to find out the record that I just created. Unfortunately is not like that, to manage to retrieve the record you just created you need to run the plugin in an asynchronous way. Otherwise as soon as you query the context (even if the record should already be there) you will receive a funny “null” as the result of the Linq query. Now if you keep that in mind should be easier to sort out weird errors.

NOTE: I wrote this article some time ago, the last paragraph is incorrect. There are multiple ways to perform the record creation and the example was maybe working for some CRM 2011 release.

I just link a couple of article that were useful for me: link1 link2

Leave a Reply

Your email address will not be published. Required fields are marked *