Friday, 23 August 2013

Delete Event in Mscrm 2011

  
context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
if (context.InputParameters.Contains("Target") &&
 context.InputParameters["Target"] is EntityReference)
{
if (context.MessageName == "Delete")
{
 // Code to be executed during Delete event
}
}

Whereas Create / Update events work as follows

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


if (context.InputParameters.Contains("Target") &&
 context.InputParameters["Target"] is Entity)
{
  
 if (context.MessageName == "Create")
 {
//Code to be executed during Create event of an entity
}

   if (context.MessageName == "Update”)
{
//Code to be executed during Update event of an entity
}

}