Real Time Workflow and Plugin, Which One is Executed First?

Last weekend when I was preparing my presentation slide for the upcoming Dynamics CRM User Group regarding some gotchas in plugin development and with a short discussion regarding Real Time Workflow, there is a question in mind: If there is a Plugin and Real Time Workflow that registered on the same event, for example on update of field A on Contact entity, which one that triggered first? I’ve tried to find Microsoft’s documentation and could not find it, so in case anyone could point out the article/documentation, please let me know.

So to answer my own question, I setup a simple Real Time Workflow to update ‘jobtitle’ field to ‘Workflow’ on Contact entity every time I change the first name. And a plugin to update ‘jobtitle’ field to ‘Plugin’ on Contact entity every time I change the first name. To test this method, I did a bulk edit on contact record to change all their first name. And the result is… Plugins are executed first, then the Real Time Workflow. This is a conclusion of the test, as all of the records that I just bulk-edited has the value of Workflow, which mean the value specified will be the one that executed later.

Workflow

I hope this help us in designing the solution with multiple event-based processes. And to manage these execution order there’s a plugin for the famous XrmToolbox here: http://mscrmtools.blogspot.com.au/2014/04/new-xrmtoolbox-plugin-synchronous.html

Note: I personally would prefer not to mix Plugin and Real Time Workflow together to avoid confusion by putting the custom process that handled by the plugin to custom workflow activity and execute that custom workflow activity within the Real Time Workflow. However, there might be a case where the solutions are developed by multiple vendors and this kind of scenario could happened.