Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Mass delete duplicate contacts

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

Hello everybody,

I work with Dynamics 365. 4447737.Capture.PNG

For a year, we worked whithout portal so we had Duplicate Dectection rule which avoided the creation of duplicate contacts. But now we have the portal, so customers create their contact account through the portal but the Duplicate Dectection rule don't work for the contact who are created through the portal, it works only if we create the contact directly through the CRM.
So, today we have a problem. We have around 9000 duplicate contacts.

With the bulk detection (5000 entries per 5000 entries) it will take a month to delete all of them (if we spend 2 minutes for each contact)

So, do you have an idea to delete them faster than the bulk detection ?

*This post is locked for comments

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Mass delete duplicate contacts

    Hello RaphaelH,

    Can you please provide me the duplicate records deactive C# code. It will be most helpful for me.

    Thank for your support....

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Mass delete duplicate contacts

    Can you please provide the success console code 

  • Verified answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Mass delete duplicate contacts

    Instead of delete the duplicate contacts, I desactivate them because when the contact is linked to an incident (case) we can't delete it.

    We have successfully developed a C# solution to detect duplicate contact and keep the main contact of these duplicate contacts.

    I share you the source code (this link is secured):

    www.fichier-zip.com/.../duplicatedetection

    Thanks for your help.

    Regards,

    Raphaël HENIN.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Mass delete duplicate contacts

    Hello,

    With the BulkDetectDuplicates.cs I tried to retrieve the list of duplicate contacts (generated by bulkdetection) but I can't. I can't get Contact objects. Do you know how to do that? I tried this :

    var duplicateContact = results.Entities.Select((contact) => (contact));

    But I can't access Attributes Lastname, EMailAddress1, etc...

  • Suggested answer
    Rawish Kumar Profile Picture
    Rawish Kumar 13,756 on at
    RE: Mass delete duplicate contacts

    Hi Raphael,

    Please have a look msdn.microsoft.com/.../bb337024(v=vs.110).aspx

    I believe you should be able to remove the first object entry in the entity collection.   You just remove one record - others you continue to delete. I hope this makes sense.

  • Suggested answer
    gdas Profile Picture
    gdas 50,089 on at
    RE: Mass delete duplicate contacts

    Hello ,

    Seems this is complex to give the prompt in console application , you may implement the complete decision making logic in your console rather than prompt or may be you introduce a flag field  in your contact entity which will update by console application , let say it is option set field  with value  -- Duplicated Detected , Approved for Deletion , Don't Delete.

    So now you can create a view with filter condition where  option set field value "Duplicate Detected " , open one by one and check and bulk update option set field value  with Approve for Deletion . In the next run of you schedule batch jobs all the contact with optionset field value "Approve for Deletion" will be deleted .

    Hope this helps.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Mass delete duplicate contacts

    Yes, it's ok but there is one problem. The bulk detect duplicate contact and prompt us if we want to delete them, if we say "yes", all the duplicate contact are delated even the main contact. For example :

    LastName : Test / Email Address : test@test.com => main contact that we want to keep

    LastName : Test2 / Email Address : test@test.com => the duplicate contact of the main contact (the filter is email address).

    The bulk delete both, but we want to keep the contact (The main contact will be identified in relation to his "modification date" field).

  • Rawish Kumar Profile Picture
    Rawish Kumar 13,756 on at
    RE: Mass delete duplicate contacts

    Should be okay!

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Mass delete duplicate contacts

    I have successfully executed the code. I want to work with Contact Entity. Currently, the code works with Account Entity. I will do the modification and do a feed back

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Mass delete duplicate contacts

    Okey thank you !

    I'm looking on the sample code that you shared me, try to understand it to see how it works and I come back here if I have questions.

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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,329 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans