+ Start a Discussion
mac adminmac admin 

Test class for the trigger

Hi everyone,
Can anyone help me in writting test class for below calss.
trigger verifyUG on UnderLdes__c (after insert) {

Set<String> Email = new Set<String>();
Set<String> PhoneNumberSet = new Set<String>();

list<Form_Leads__c> test1  = new  list<Form_Leads__c> ();
list<Form_Leads__c> test2  = new  list<Form_Leads__c> ();

for(UnderLdes__c IL : trigger.new){
	if (IL.Email__c != null){
		Email.add(IL.Email__c);
	}
	if (IL.Cell_Phone_Number__c!= null){
		PhoneNumberSet.add(IL.Cell_Phone_Number__c);
	}
}
test1 = [SELECT id, Email__c, Cell_Phone_Number__c, Converted_Status__c FROM Form_Leads__c WHERE Email__c IN : Email AND 
Cell_Phone_Number__c IN: PhoneNumberSet limit 5000 ];


if(test1.size() > 0){
	for(Form_Leads__c t :test1){
		Form_Leads__c fl = new Form_Leads__c();
		f1.Id = t.Id;
		fl.Applied__c = true;
        fl.Converted_Status__c = 'Matched';
        test2.add(fl);
	}
}
if(test2.size() > 0{
	update test2;
}
}

 
Leo10Leo10
Hi, 
Try this
@istest
public class triggerTestClass{
public static testMethod void Testmethod1(){
    
    UnderLdes__c und= new UnderLdes__c(Email__c='demo@gmail.com',Cell_Phone_Number__c='999999999'); 
    insert und;
    Form_Leads__c formLead= new Form_Leads__c(Email__c='demo@gmail.com', Cell_Phone_Number__c = '999999999', Converted_Status__c='Active');
    insert formLead;    
    }

}

 
mac adminmac admin
 Hi NABEEL ,
Thanks for the reply. the below code is not covered.
if(test1.size() > 0){
   for(Form_Leads__c t :test1){
       Form_Leads__c fl = new Form_Leads__c();
      f1.Id = t.Id;
      fl.Applied__c = true;
        fl.Converted_Status__c = 'Matched';
        test2.add(fl);
   }
}
if(test2.size() > 0{
   update test2;
}
can you help me here.
Leo10Leo10
Try this 
@istest
public class triggerTestClass{
public static testMethod void Testmethod1(){

    list<Form_Leads__c> FLead = new list<Form_Leads__c>();
  
    UnderLdes__c undLead1= new UnderLdes__c(Email__c='demo@gmail.com',Cell_Phone_Number__c='999999999'); 
    insert undLead1;
    Form_Leads__c formLead1= new Form_Leads__c(Email__c='demo@gmail.com', Cell_Phone_Number__c = '999999999', Converted_Status__c='Active',Applied__c=false);
    FLead.add(formLead1); 
    Form_Leads__c formLead2= new Form_Leads__c(Email__c='demo@gmail.com', Cell_Phone_Number__c = '999999999', Converted_Status__c='Hold',Applied__c=false);
    FLead.add(formLead2); 
    Form_Leads__c formLead3= new Form_Leads__c(Email__c='test@gmail.com', Cell_Phone_Number__c = '222222222', Converted_Status__c='Hold',Applied__c=false);
    FLead.add(formLead3);
    insert FLead;    
    }

}

and you have to change  f1.Id = t.Id; into  fl.Id = t.Id; .