Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

delete duplicate records from 2011 dynamics CRM

Posted on by 1,558

Hello All,

I want to delete duplicate contact records on the basis of duplicate "Email" addresses from 2011 dynamics CRM version. Could anyone please suggest me here.

Thanks,

*This post is locked for comments

  • Suggested answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: delete duplicate records from 2011 dynamics CRM

    Hi Tin,

    if you solved the problem thanks to an answer, please mark it as verified to encourage the community to provide more and more a better support. Thank you. Francesco

    If you found the answer helpful, please mark as Verified 

    Join my network on LinkedIn      Follow me on Twitter 

    Thank You & Best Regards

    Francesco Picchi

    Microsoft Dynamics CRM Consultant, Bologna+Milano, ITALY

    Independent Contractor

    http://www.francescopicchi.com

  • Suggested answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: delete duplicate records from 2011 dynamics CRM

    Hi Tin ,

    there is the duplication detect tool of CRM, but is a one-o-one job.

    I think you need a batch job.

    I wrote it down for you.

    public static void DeleteDuplicatedContacts(IOrganizationService svc)
    {
        List<string> emailaddresslist = new List<string>();
    
        QueryExpression query = new QueryExpression("contact");
        query.ColumnSet = new ColumnSet("emailaddress1");
        query.Criteria.AddCondition("emailaddress1", ConditionOperator.NotNull);
        query.Orders.Add(new OrderExpression("emailaddress1", OrderType.Ascending));
        List<Entity> entitylist = svc.RetrieveMultiple(query).Entities.ToList();
    
        foreach (Entity entity in entitylist)
        {
            string emailaddress = entity.GetAttributeValue<string>("emailaddress1");
    
            if (!emailaddresslist.Contains(emailaddress))
                emailaddresslist.Add(emailaddress);
            else
                svc.Delete(entity.LogicalName, entity.Id);
        }
    }

    Please let me know if you solve.

    If you found the answer helpful, please mark as Verified 

    Join my network on LinkedIn      Follow me on Twitter 

    Thank You & Best Regards

    Francesco Picchi

    Microsoft Dynamics CRM Consultant, Bologna+Milano, ITALY

    Independent Contractor

    http://www.francescopicchi.com

  • Tin Profile Picture
    Tin 1,558 on at
    RE: delete duplicate records from 2011 dynamics CRM

    Thanks Francesco, Did we have any OOB feature ?

    Above steps for custom workflow or plugin?

  • Suggested answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: delete duplicate records from 2011 dynamics CRM

    Hi Tin ,

    proceed as follows:

    1) retrieve all contacts, selecting only emailaddress1

    2) setup a string list, we name "EmailAddressList"

    3) loop all records

    4) for each record, check if emailaddress1 exists into EmailAddressList.

    5) If not, add it to list

    6) If exists, call a service.Delete over the current contact record

    Please let me know if you solve.

    If you found the answer helpful, please mark as Verified 

    Join my network on LinkedIn      Follow me on Twitter 

    Thank You & Best Regards

    Francesco Picchi

    Microsoft Dynamics CRM Consultant, Bologna+Milano, ITALY

    Independent Contractor

    http://www.francescopicchi.com

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans