web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics 365 | Integration, Dataverse...
Suggested Answer

Create Contact Plugin fires multiple times on Lead qualification with duplicate detection

(0) ShareShare
ReportReport
Posted on by 15

Hello,

I have developed a Plugin that will fire when a Contact is created, the plugin fires on PreOperation. The intent is to validate the contact before it is created.

We have also turned on duplicate detection so that this validation does not happen on duplicate records.

What I am noticing is that when we go to qualify a lead my plugin will fire when I don't expect it to. See the following examples:

  • Qualify Lead when a duplicate contact exists
  • Associate lead with contact, my plugin runs on a contact that doesn't seem to be created
  • Lead is associated with contact

The second scenario:

  • Qualify Lead when a duplicate contact exists
  • Do not associate with the contact, create a new contact
  • My plugin fires twice, only one contact is created

Does anyone know what is going on here?  Is there something happening because I am firing on PreOperation?

Thanks

I have the same question (0)
  • Vijay Tailor Profile Picture
    431 on at

    Hi Jeri,

    when the lead will qualify auto contact is created ( you can disable this feature).

    This is happing bcoz you register the plugin on "Create" Event that is the reason two contacts is created.

    One is contact created manually another one created when the lead will be qualify.

    so if you don't want contact creation on lead qualify in that scenario you can disable this option please find below URL will help you for more details.

    docs.microsoft.com/.../qualify-lead-convert-opportunity-sales

    Thanks,

  • Jerimiah Profile Picture
    15 on at

    Hello Vijay,

    Depending on the scenario we want the qualify lead to create a contact. If the lead should be a new contact, a contact should be created. If the lead should be associated with a current contact, then it shouldn't create a contact. What we are seeing is that in either scenario my plugin is firing 1 additional time than it should.

    When qualifying a lead, our users will get the dialog asking if they want to create an account, contact and opportunity. In my tests, I only select yes for create contact. I then get a dialog that say a contact was found with that name, and it asks me to associate the lead with that contact or create a new contact.  When associating the lead, I expect no contacts to be created, but my plugin fires once. When creating a new contact, I expect one contact to be created, but my plugin fires twice.

  • Suggested answer
    Vijay Tailor Profile Picture
    431 on at

    In that Scenario - In your plugin before create Record check the duplicate record using Organization service.

    You can programmatically check whether an entity is a duplicate or will be a duplicate before creating or updating it by using the RetrieveDuplicatesRequest class.

    var account = new Account();

    account.Name = "Sample Account";

    var request = new RetrieveDuplicatesRequest()

    {

       BusinessEntity = account,

       MatchingEntityName = account.LogicalName,

       PagingInfo = new PagingInfo() { PageNumber = 1, Count = 50 }

    };

    var response = (RetrieveDuplicatesResponse)svc.Execute(request);

    if (response.DuplicateCollection.Entities.Count >= 1)

    {

       Console.WriteLine("{0} Duplicate records found.", response.DuplicateCollection.Entities.Count);

    }

    For More Details Please check below url.

    docs.microsoft.com/.../detect-duplicate-data

  • Jerimiah Profile Picture
    15 on at

    I don't perform the Create action in my plugin. It fires on PreOperation of Create. So I receive the record that will be created, before it is saved in the database. I then modify a few fields and let it continue on it's way to create the record.

    Checking duplicates in my plugin doesn't help for the scenario where a user might want to create someone with a duplicate name.

  • Jerimiah Profile Picture
    15 on at

    This is my suspicion of what might be going on.

    When we qualify a lead, D365 will create a contact. Before saving it to the database, during the PreOperation phase, D365 checks for a duplicate record. If one is found, it stops the contact create and alerts the user. The user then decides if they should create a contact or add to an existing contact. If the user wants a new contact created D365 will then create another contact record and let this finish PreOperation.

    So far the only solution I've found is to run on PostOperation, after this has all transpired. So my plugin will only run if the contact was actually saved in the database.

    Can anyone confirm if this is what D365 is doing?

  • meelamri Profile Picture
    13,218 User Group Leader on at

    I will do same :) 

  • Suggested answer
    meelamri Profile Picture
    13,218 User Group Leader on at

    Please deploy your plugin in a preoperation. And check the parent context message with some tracing log.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Microsoft Dynamics 365 | Integration, Dataverse, and general topics

#1
Subra Profile Picture

Subra 144

#2
11manish Profile Picture

11manish 134

#3
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 88 Super User 2026 Season 1

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans