function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Joe Williams 19Joe Williams 19 

Duplicate lead alert

How can I accomplish this? "write triggers to send an email alert when a duplicate record is created or create a Process Builder to which auto launches a flow"

Looking to receive the alerts to one specific email address..
Jasper WallJasper Wall
Hi Joe,
It is better to prevent a user to create a duplicate record in your organization.
you can write a trigger like this,
trigger FindDupes on Lead (before insert, before update) {
  for (Lead myLead : Trigger.new) {
    if (myLead.Email != null) {
      List<Contact> dupes = [SELECT Id FROM Contact
                               WHERE Email = :myLead.Email];
      if (dupes.size() > 0) {
        myLead.Dupe_Contact__c = dupes[0].Id;
      } else {
        myLead.Dupe_Contact__c = null;
      }                             
    }
  }
}

Find more details in 
http://www.sfdc99.com/2013/10/19/example-how-to-write-a-deduping-trigger-for-leads-and-contacts/


Mark it as the best answer if it helps,

Thanks,
Balayesu
Saurabh BSaurabh B
Hi Joe,
Rather than writing a code, you could use two other ways to accomplish this,
  1. You can go to setup > Duplicate Management and create a Duplicate Rule. This rule will prevent users from entering Leads and show alerts.
  2. Other option is you install Free DupeCatcher tool in your Org. This too will allow you to prevent duplicates and send alerts. https://appexchange.salesforce.com/listingDetail?listingId=a0N30000003IYLlEAO

Hope this help!

Please mark this as Best Answer if it helps you!