Search code examples
c#pluginsdynamics-crm-2011microsoft-dynamicsdynamics-crm-2015

Dynamics CRM - Identifying whether a Contact has been merged in a PreContactUpdate plugin


I've got a plugin that fires when a contact gets updated. This also gets fired when two contacts get merged. What's the easiest way to identify whether contacts have been merged within the PreContactUpdate plugin?

code:

    protected void ExecutePreContactUpdate(LocalPluginContext localContext)
    {
        if (localContext == null)
        {
            throw new ArgumentNullException("localContext");
        }

        Entity contact = (Entity)localContext.PluginExecutionContext.InputParameters["Target"];

        // check if contacts have been merged
        ....
    }

Solution

  • Try following:

    if (localContext.PluginExecutionContext.ParentContext != null &&
    localContext.PluginExecutionContext.ParentContext.MessageName == "Merge")
    {
    //When records are merged
    }
    else
    {
    //All other cases
    }