Search code examples
c#pluginsdynamics-crmmicrosoft-dynamicsdynamics-crm-2015

Dynamic CRM - Identifying whether a Contact has been generated from a Lead in a PreContactCreate plugin


I've got a PreContactCreate plugin that fires on the Contact entity. This also gets fired when the 'Quantify' button is clicked on a Lead. Within the plugin in ExecutePreContactCreate(), how can I identify whether a Lead was quantified rather than for example, a new Contact was created directly in the Contact section of CRM?

For example, there's no ContactA in Contacts. I click on 'Qualify' button on LeadA (for ContactA). The PreContactCreate plugin fires and within this I want to determine whether this contact is being generated from qualifying a lead.


Solution

  • There are couple of ways but as for me easiest is to check originatingleadid from contact like following:

    var target = context.InputParameters["Target"] as Entity;
    if (target.Contains("originatingleadid")
    {
    //your logic when contact is created during qualification
    }
    else
    {
    //other sources of creation of contact
    }