Delete Event in CRM 2011 Plug-In

Today, I have written a plug-in which fires on record delete message. I have deployed it successfully and when I test it, the code is not firing and even I don’t see any error message. I went further and debugged the code and found the cause of the issue.
Event
Type
Delete
context.InputParameters[“Target”]
EntityReference
Create
context.InputParameters[“Target”]
Entity
Update
context.InputParameters[“Target”]
Entity
So your code should be as follows

Delete
if (context.InputParameters.Contains(“Target”) && context.InputParameters[“Target”is EntityReference)
{
    if (context.MessageName == “Delete”)
    {
         // Your code
    }
}
Create and Update
if (context.InputParameters.Contains(“Target”) && context.InputParameters[“Target”is Entity)
{
    if (context.MessageName == “Create”)
    {
         // Your code
    }
    if (context.MessageName == “Update”)
    {
         // Your code
    }
}
Happy CRM’ing
Gopinath

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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