+ Start a Discussion
bikla78bikla78 

Duplicate Contact Trigger

This trigger checks that a contact with the same first and last is not saved in the database with the same accountid.  This works well but has anyone written any APEX with regular expressions in regard to duplicate record prevention? I was thinking it could check for LIKE name matches as well

 

Stephen Smith would be same as

Steve Smith

Steeeve Smith

Seve Smith

Steve Smit

 

etc...

 

I think alot of you guys will appreciate this post since duplicate record prevention is so common today


trigger ContactDuplicateTrigger on Contact (before insert) {
   for (Contact c : Trigger.new){
      
      Contact[] contacts= [select id from Contact where FirstName = :c.FirstName and LastName = :c.LastName and accountid = :c.accountid];
      
      if (contacts.size() > 0) {
          c.LastName.addError(' Contact already exists with this company');
      }    
   }
}

 

WesNolte__cWesNolte__c

Ah that would be cool, but not very simple. You'd have to build some sort of fuzzy logic, and even then, you'd have to present the user with the option to check whether it had gotten it correct.

 

Very good idea though. I think you've found a niche that could make you a rich man/woman:)

 

Wes

JimRaeJimRae

This is a very interesting idea.  I haven't worked with Regular expressions much myself, but I am sure there are a lot of posters here that have.

CRMFusion has a commercial product that has this built in called Dupeblocker.  This is what we use at my company. It is a great product, very powerful, and is optimized to support very large data sets (we have over 500,000 contacts).