Plugins are usually set to run as the calling user but sometimes you need to run a plugin with System User privileges.
Before I explain how, we should first look at the why and how you impersonate users inside a plugin
I have been writing a bit about plugins recently
- Plugin Deployment Options
- CRM Plugins – Stopping infinite loops and understanding PluginExecutionContext.Depth
- CRM 2013 – Understanding SystemJobs and Async Plugins
For some step by step guides to creating plugins check out the CRM Code examples section on the page Hosk’s CRM Developer Articles, I created some Youtube videos CRM 2013 Plugins
What is impersonation
When you create a plugin in CRM (step by step blog post here) you write an execute method which gets passed in
IServiceProvider serviceProvider
This has lots of variables and objects such as
- IPluginExecutionContext
- ITracingService
- IOrganizationServiceFactory
You use the IOrganisationServiceFactory to create a IOrganizationService. The IOrganizationService…
View original post 842 more words