Bhav
Bhav

Reputation: 2207

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
        ....
    }

Upvotes: 1

Views: 293

Answers (1)

Andrew Butenko
Andrew Butenko

Reputation: 5446

Try following:

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

Upvotes: 2

Related Questions