You need to sign in to do that
Don't have an account?
trigger to check for duplicate last name in leads and if found duplicates performs checkbox as checked
Hi ,
I need to write a trigger which checks all the leads and if any lead had duplicate lastname then in that i have to mark checkbox via trigger,for that i have written a trigger but it is not working can anyone help me..
my trigger is:
trigger LeadDuplicatePreventer on Lead (before insert ,after update)
{
List<Lead> lead1 = new List<Lead>();
List<Lead> lead2 = new List<Lead>();
for (Lead L1 :trigger.new)
{
for(Lead L2:trigger.new)
{
if(L1.LastName == L2.LastName)
L1.Duplicate_Lastname1__c = true;
exit();
}
}
}
but is showing an error method does not exist exit();
I need to write a trigger which checks all the leads and if any lead had duplicate lastname then in that i have to mark checkbox via trigger,for that i have written a trigger but it is not working can anyone help me..
my trigger is:
trigger LeadDuplicatePreventer on Lead (before insert ,after update)
{
List<Lead> lead1 = new List<Lead>();
List<Lead> lead2 = new List<Lead>();
for (Lead L1 :trigger.new)
{
for(Lead L2:trigger.new)
{
if(L1.LastName == L2.LastName)
L1.Duplicate_Lastname1__c = true;
exit();
}
}
}
but is showing an error method does not exist exit();
Is exit() any custom method in trigger, because there is not such native method in Apex. Although I have updated the trigger code. You can use this code: Let me know, if you need any other help.
Thanks,
Neetu
replace
exit();
with
break;
Thx
Greetings,
Lukasz
If need to update the checkbox automatically for duplicate lastnames then the above trigger works??
thanks
kiran
Let suppose i am having two leads records with name kiran punuru and kirankumar punuru where punuru as lastname then when i go that record and if i update any value it is not making the check box as checked why ? any reason for that..
Like this above example as mentioned there are many leads with duplicate lastnames ,instead of going to each and every record does it make the checkbox as true for existing records?
Thanks Neetu,Lukasz
Try my code and it will work for all the use cases. Let me know if there is any issue or you need any other help.
Thanks,
Neetu
Your Code is working when iam creating a new lead with duplicate last name when iam updating the record it is no changing the checkbox.
Thanks
kiran
As now, my code will run only if you have changed the LastName in case of update, but if this not your requirement. Use the below one: This will also helps you to uncheck the Duplicate checkbox, once you have updated the lastname with something which is not duplicate.
Thanks,
Neetu
If still you have any issue, you can contact me on my skype id: neetu.bansal.5
Thanks,
Neetu
Trigger LeadDuplicatePreventer: Helper Class LeadHelper: I checked it and it works. New records and existing database records are stamped.
Hope this helps.
Lukasz
The trigger which u have mentioned above is updating the checkbox for non duplicate records also..
Thanks
kiran