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
nish5nish5 

Intimate about repeated Lead.

Hi ,

I need to write a trigger for repeated Lead.That are multiple scenario that has to follow:-
a)should show repeated lead with Name ,Mobile  & Email Id
b)should intimate no. of times it apper.
c)should show as repeted lead but if marked check-box as repeated then should save the record. 
Can anyone provide me a sample code for this. 
Nishant Prajapati 10Nishant Prajapati 10
Hi Nishi , Please try with the follwing sample code, and let know if it is useful or not
trigger RepeatedLead on Lead(Before Insert){
    //these three List hold data for match with existing records
    List<String> nameList = new List<String>();
    List<String> emailList = new List<String>();
    List<String> mobilePhoneList = new List<String>();
    List<Lead> checkExistingLead = new List<Lead>();
    for(Lead l : trigger.new){
        if(l.Name <> null && l.MobilePhone <> null && l.Email <> null){
            nameList.add(l.Name);
            emailList.add(l.Email);
            mobilePhoneList.add(l.MobilePhone);
        }
    }
    checkExistingLead = [select Name, MobilePhone, Email from Lead WHERE Name IN: nameList AND Email IN: emailList AND MobilePhone IN: mobilePhoneList];
    if(checkExistingLead.size() > 0){
        // your logic to check repetitive leads 
        // you have now list of those leads which matches with leads from trigger.new
        // all you have to do is to check leads from trigger.new and leads from existing leads
    }
}

 
mukesh guptamukesh gupta
Hi Nishi,

Please use this trigger and need to create  CHECK BOX on lead object.
trigger CheckDuplicateLead on Lead(Before Insert){
    List<String> listName = new List<String>();
    List<String> listEmail = new List<String>();
    List<String> listMobilePhone = new List<String>();
    List<Lead> duplicateLead = new List<Lead>();
    for(Lead l : trigger.new){
        if(l.Name != null && l.MobilePhone != null && l.Email != null){
            listName.add(l.Name);
            listEmail.add(l.Email);
            listMobilePhone.add(l.MobilePhone);
        }
    }
    duplicateLead = [select Id, Name, MobilePhone, Email from Lead WHERE Name IN: listName AND Email IN: listEmail AND MobilePhone IN: listMobilePhone];
    if(duplicateLead.size() > 0 && checkBox == true){
         //duplicate lead created and saved when check box is true;

    }else{
       system.debog(duplicateLead.size()); ///use to count duplicate lead
}
}
Kindly mark my solution as the best answer if it helps you.

Thanks
Mukesh