You need to sign in to do that
Don't have an account?

please help me with test class...
trigger test on Lead (after insert) { try { Set<String> setEmails = new Set<String>(); Map<String, Contact> mapCons = new Map<String, Contact>(); List<Contact> lstContact = new List<Contact>(); List<Contact> lstCont = [Select Id, Name , Email_2__c from Contact where Email_2__c in : setEmails]; for(Contact objC : lstCont) { mapCons.put(objC.Email_2__c, objC); } for(Lead ld : Trigger.new) { if(mapCons.containsKey(ld.Email)) { //Contact exist in system show error. ld.addError('Contact exist in System with email address '+ ld.Email); }else { Contact objC= new Contact(); objC.FirstName=ld.FirstName; objC.LastName=ld.LastName; objC.RecordTypeName__c='Candidates'; lstContact.add(objC); } } if(lstContact.size() > 0 ) insert lstContact; }catch(Exception ex) { Trigger.new[0].adderror('Error ----'+ ex.getMessage()); } }
can someone help me with the test class of the above class....thanks....
Hi,
Try the below code as reference:
@isTest
private class TestTrigger2
{
public static testMethod void testPermissionsUser()
{
try
{
Contact c1=new Contact(Lastname='c1',Email_2__c='aj@gmail.com');
insert c1;
Contact c2=new Contact(Lastname='c2');
insert c2;
Lead l1=new Lead(LAstname='l1',Company='cm1',Email='aj@gmail.com');
insert l1;
}
catch(Exception e)
{
throw e;
}
}
}
Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.
how to check for the email thing...