How To Get The Target Entity In Microsoft CRM Plugins With C#

Typically you want to use the target entity in Microsoft CRM plugins to validate, calculate and/or manipulate values. By the time you register a plugin step you have to set the primary entity, which later will be your target entity.

Message and Primary Entity Settings - Target Entity In Microsoft CRM Plugins
Set the message and primary entity of the plugin step

In your plugin code, where you implement the implementation of IPlugin, which needs a Execute method with a parameter for IServiceProvider, you now can create a instance of the IPluginExecutionContext.

With the context you now have access to all the input parameters which are transferred to the plugin.

Usually the primary entity is accessible with the key “Target” within the InputParameters List.

However, you should always make some kind of validation if the value is available and has the correct type. If so, you can parse the value to an Entity and work with it from now on.

When you are using early-bound classes you can parse the entity further to an specific kind of entity like an contact.

The advantage of early-bound classes is, that you can access all available properties and use auto-completion instead of accessing all properties via keys.


In the official Microsoft CRM SDK you’ll find the used Plugin Registration Tool, other tools and sample code by Microsoft.

1 thought on “How To Get The Target Entity In Microsoft CRM Plugins With C#”

Leave a Comment

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.