How To Start with MS CRM 2011 Plugin?

PlugIn Creation Steps:

Step No 1:

Import required Name Spaces.

using System;

using System.ServiceModel;                                    // CRM 2011: add reference to System.ServiceModel – WCF

// Microsoft Dynamics CRM namespace(s)

using Microsoft.Xrm.Sdk;

using Microsoft.Xrm.Sdk.Query;   

Step No 2:

// get the required interfaces from the service provider

            IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));

            // CRM 2011: Microsoft.Crm.Sdk.IPluginExecutionContext -> Microsoft.Xrm.Sdk.IPluginExecutionContext

            IOrganizationServiceFactory factory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));

            // CRM 2011: NEW

            ITracingService tracer = (ITracingService)serviceProvider.GetService(typeof(ITracingService));

            // CRM 2011: NEW

            tracer.Trace(“ENTER: BMIMeasurement.CalculateBodyFatMeasurement.Execute”);

Step No 3: 

// Check if the input parameters property bag contains a target

            // of the create operation and that target is of type Entity.

            if (context.InputParameters.Contains(“Target”) &&

               context.InputParameters[“Target”] is Entity)


                // Obtain the target business entity from the input parmameters.

                targetEntity = (Entity)context.InputParameters[“Target”];

                // Verify that the entity represents our custom entity contoso_bmimeasurement.

                if (targetEntity.LogicalName != “contoso_bmimeasurement”)


                                                                    Place Your Logic here








 Step No 4:




catch (FaultException<OrganizationServiceFault> ex)

            // CRM 2011: System.Web.Services.Protocols.SoapException -> System.ServiceModel.FaultException<Microsoft.Xrm.Sdk.OrganizationServiceFault>


                throw new InvalidPluginExecutionException(String.Concat(“An error occurred in the PersonalMeasurement.SaveBodyFatMeasurement plug-in.”, ex.Message, Environment.NewLine, ex.StackTrace));

                // CRM 2011: Microsoft.Crm.Sdk.InvalidPluginExecutionException -> Microsoft.Xrm.Sdk.InvalidPluginExecutionException



One thought on “How To Start with MS CRM 2011 Plugin?

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s