You need to sign in to do that
Don't have an account?
M Sreekanth
Way i am not getting codecoverage i think my test class is everything is fine
Trigger code:-
-------------------
/* Write a trigger that will prevent a user from creating a lead that already existed as a Contact.
* We'll use the lead/contacts email address to detect duplicates.
* Whenever the lead is created or updated.
1. Lead has an email address
2. Try to find a matching contact based or email address.
3. If a match is found, give the user an error.
4. If a match is not found, do nothing.
== if email matched based on contact record in the lead record at the time of creating through an error
*/
trigger DuplicateContactsOnLead on Lead (before insert,before update) {
for(lead l:Trigger.new){
if(l.Email != Null){
list<contact> con =[SELECT ID FROM Contact WHERE EMAIL=:L.Email];
if(con !=null && con.size()>0){
// string ErrorMsg ='Duplicate Value Found!!';
// ErrorMsg +='RecordId is:-'+con[0].id;
l.Email.addError('Duplicate Value Found!! Record Id Is:='+con[0].id);
}
}
}
}
-----------------------------------------------------------------------------------------------------
Test Class Code:-
--------------------------
@isTest
private class TestClass_DuplicateContactsOnLead {
static testMethod void testme(){
contact c = new contact(LastName='testing',Email='sreekanth@gmail.com');
insert c;
lead l = new lead(LastName='TestLead',Email='sreekanth@gmail.com',Company='wipro',Status='Open - Not Contacted');
if(l.Email != Null){
list<contact> con =[SELECT ID FROM Contact WHERE EMAIL=:L.Email];
if(con !=null && con.size()>0){
l.Email.addError('Duplicate Value Found!! Record Id Is:='+con[0].id);
}else{
insert l;
}
}
}
}
-------------------
/* Write a trigger that will prevent a user from creating a lead that already existed as a Contact.
* We'll use the lead/contacts email address to detect duplicates.
* Whenever the lead is created or updated.
1. Lead has an email address
2. Try to find a matching contact based or email address.
3. If a match is found, give the user an error.
4. If a match is not found, do nothing.
== if email matched based on contact record in the lead record at the time of creating through an error
*/
trigger DuplicateContactsOnLead on Lead (before insert,before update) {
for(lead l:Trigger.new){
if(l.Email != Null){
list<contact> con =[SELECT ID FROM Contact WHERE EMAIL=:L.Email];
if(con !=null && con.size()>0){
// string ErrorMsg ='Duplicate Value Found!!';
// ErrorMsg +='RecordId is:-'+con[0].id;
l.Email.addError('Duplicate Value Found!! Record Id Is:='+con[0].id);
}
}
}
}
-----------------------------------------------------------------------------------------------------
Test Class Code:-
--------------------------
@isTest
private class TestClass_DuplicateContactsOnLead {
static testMethod void testme(){
contact c = new contact(LastName='testing',Email='sreekanth@gmail.com');
insert c;
lead l = new lead(LastName='TestLead',Email='sreekanth@gmail.com',Company='wipro',Status='Open - Not Contacted');
if(l.Email != Null){
list<contact> con =[SELECT ID FROM Contact WHERE EMAIL=:L.Email];
if(con !=null && con.size()>0){
l.Email.addError('Duplicate Value Found!! Record Id Is:='+con[0].id);
}else{
insert l;
}
}
}
}
Can you try the below test class.
Let me know if you face any issues.
If this solution helps, Please mark it as best answer.
Thanks,
All Answers
Can you try the below test class.
Let me know if you face any issues.
If this solution helps, Please mark it as best answer.
Thanks,
Thank you Praveen,Spending on time for this