You need to sign in to do that
Don't have an account?
Akshay Alandkar
want test class for this
public class ContactHelperClass
{
//email and phone number fields cant be duplicate
public void PhoneAndEmailDuplicate(List<Contact> contact1)
{
Set<String> NewEmailSet=new Set<String>();
Set<String> NewPhoneSet=new Set<String>();
for(Contact con:contact1)
{
if(con.Email !=null)
{
NewEmailSet.add(con.Email);
}
if(con.Phone !=null)
{
NewPhoneSet.add(con.Phone);
}
}
List<Contact> existingcontList=[SELECT Id,Name,Email,Phone FROM Contact WHERE Email != null OR Phone!=null];
for(Contact con:contact1)
{
for(Contact con1:existingcontList)
{
if(NewEmailSet.contains(con1.Email))
{
con.Email.addError('A Contact with the Same email Address alredy exist in the System.');
}
if(NewPhoneSet.contains(con1.Phone))
{
con.Phone.addError('A Contact with the Same Phone Number alredy exist in the System.');
}
}
}
}
{
//email and phone number fields cant be duplicate
public void PhoneAndEmailDuplicate(List<Contact> contact1)
{
Set<String> NewEmailSet=new Set<String>();
Set<String> NewPhoneSet=new Set<String>();
for(Contact con:contact1)
{
if(con.Email !=null)
{
NewEmailSet.add(con.Email);
}
if(con.Phone !=null)
{
NewPhoneSet.add(con.Phone);
}
}
List<Contact> existingcontList=[SELECT Id,Name,Email,Phone FROM Contact WHERE Email != null OR Phone!=null];
for(Contact con:contact1)
{
for(Contact con1:existingcontList)
{
if(NewEmailSet.contains(con1.Email))
{
con.Email.addError('A Contact with the Same email Address alredy exist in the System.');
}
if(NewPhoneSet.contains(con1.Phone))
{
con.Phone.addError('A Contact with the Same Phone Number alredy exist in the System.');
}
}
}
}
Try Below Test Class Please Mark It As Best Answer If It Helps
Thank You!
All Answers
Try Below Test Class Please Mark It As Best Answer If It Helps
Thank You!