You need to sign in to do that
Don't have an account?
shakila G
Lead Duplicate check
I have 5 mobile fields in lead object
To avoid the lead duplicate I have to check all the 5 fields with each other
This my code is trying to check the duplicates. Is the correct way to check the duplicates?
Trigger leadduplicatecheck on lead(before insert,Before Update)
{
List<Lead> llist=new list<lead>();
Set<string> setMobilePhone =new set<String>();
Set<string> setWhatsapp =new set<String>();
Set<string> setMobile =new set<String>();
Set<string> setPhone =new set<String>();
Set<string> setPhoneAdd =new set<String>();
for(Lead l:Trigger.new)
{
setMobilePhone.add(l.MobilePhone);
setWhatsapp.add.(l.Whatsapp_Mobile__c);
setMobile.add.(l.Mobile_Additional__c);
setPhone.add.(l.Phone);
setPhoneAdd.add.(l.Phone_Additional__c);
}
llist=[select ID from Lead where (MobilePhone =:setMobilePhone or MobilePhone=:setWhatsapp
MobilePhone =:setMobile or
MobilePhone =:setPhone or
MobilePhone =:setPhoneAdd ) OR
(Phone =:setMobilePhone or
Phone=:setWhatsapp or
Phone =:setPhone or
Phone =:setMobile or
Phone =:setPhoneAdd ) OR
(Mobile_Additional__c =:setMobilePhone or
Mobile_Additional__c=:setWhatsapp or
Mobile_Additional__c =:setPhone or
Mobile_Additional__c =:setMobile or
Mobile_Additional__c =:setPhoneAdd ) OR
(Whatsapp_Mobile__c =:setMobilePhone or
Whatsapp_Mobile__c=:setWhatsapp or
Whatsapp_Mobile__c =:setPhone or
Whatsapp_Mobile__c =:setMobile or
Whatsapp_Mobile__c =:setPhoneAdd ) OR
(Phone_Additional__c =:setMobilePhone or
Phone_Additional__c=:setWhatsapp or
Phone_Additional__c =:setPhone or
Phone_Additional__c =:setMobile or
Phone_Additional__c =:setPhoneAdd )];
For(Lead l : Trigger.New)
{
if(Trigger.isupdate &&llist.size()>0)
{
l.adderror('Already Lead Exist with this Mobile Nuber, Duplicate');
}
if(Trigger.insert && llist.size()>0)
{
l.adderror('Already Lead Exist with this Mobile Nuber');
}
}
}
To avoid the lead duplicate I have to check all the 5 fields with each other
This my code is trying to check the duplicates. Is the correct way to check the duplicates?
Trigger leadduplicatecheck on lead(before insert,Before Update)
{
List<Lead> llist=new list<lead>();
Set<string> setMobilePhone =new set<String>();
Set<string> setWhatsapp =new set<String>();
Set<string> setMobile =new set<String>();
Set<string> setPhone =new set<String>();
Set<string> setPhoneAdd =new set<String>();
for(Lead l:Trigger.new)
{
setMobilePhone.add(l.MobilePhone);
setWhatsapp.add.(l.Whatsapp_Mobile__c);
setMobile.add.(l.Mobile_Additional__c);
setPhone.add.(l.Phone);
setPhoneAdd.add.(l.Phone_Additional__c);
}
llist=[select ID from Lead where (MobilePhone =:setMobilePhone or MobilePhone=:setWhatsapp
MobilePhone =:setMobile or
MobilePhone =:setPhone or
MobilePhone =:setPhoneAdd ) OR
(Phone =:setMobilePhone or
Phone=:setWhatsapp or
Phone =:setPhone or
Phone =:setMobile or
Phone =:setPhoneAdd ) OR
(Mobile_Additional__c =:setMobilePhone or
Mobile_Additional__c=:setWhatsapp or
Mobile_Additional__c =:setPhone or
Mobile_Additional__c =:setMobile or
Mobile_Additional__c =:setPhoneAdd ) OR
(Whatsapp_Mobile__c =:setMobilePhone or
Whatsapp_Mobile__c=:setWhatsapp or
Whatsapp_Mobile__c =:setPhone or
Whatsapp_Mobile__c =:setMobile or
Whatsapp_Mobile__c =:setPhoneAdd ) OR
(Phone_Additional__c =:setMobilePhone or
Phone_Additional__c=:setWhatsapp or
Phone_Additional__c =:setPhone or
Phone_Additional__c =:setMobile or
Phone_Additional__c =:setPhoneAdd )];
For(Lead l : Trigger.New)
{
if(Trigger.isupdate &&llist.size()>0)
{
l.adderror('Already Lead Exist with this Mobile Nuber, Duplicate');
}
if(Trigger.insert && llist.size()>0)
{
l.adderror('Already Lead Exist with this Mobile Nuber');
}
}
}
I suggest to use only one Set to add all numbers then query will be also simplify
All Answers
I suggest to use only one Set to add all numbers then query will be also simplify