+ Start a Discussion
DeveloperDeveloper 

please help me , i want 100% code covarege in bellow code . i got 87% of code caovarege.

Best Answer chosen by Developer
Leo10Leo10
@isTest

private class phonevalidation_Test{ 
	static testMethod void testMethods(){
		list<Lead> leads = new list<Lead>();
		Lead lead1 = new Lead( Lastname='Demo1', Phone='111111111', email='test@gmail.com');
		leads.add(lead1);
		Lead lead2 = new Lead( Lastname='Demo2', Phone='', email='');
		leads.add(lead2);
		insert leads;
	}
}

By mistake, I deleted my answer. Please mark this as Best Answer if it helps!

All Answers

DeveloperDeveloper
trigger phonevalidation on Lead (before insert,before update) {
   
    for (lead id: trigger.new)
    {
        if (id.phone == null)
        {
         id.adderror('phone number is mandetary');   
        }
  
    }
    for (lead id: trigger.new)
    {
        if (id.Email == null)
        {
         id.adderror('Email is mandetary');   
        }
  
    }
}







test calss:


@isTest

    private class phonevalidation_Test2{ 
    static testMethod void test1(){

    Lead le = new Lead( Phone='9807213456');
    insert le;
   
    le.MobilePhone = '0987654321';
                 
    }
}
Saurabh BSaurabh B
Hi Gopal, try this ...
 
@isTest

    private class phonevalidation_Test2{ 
    static testMethod void test1(){

    Lead le = new Lead( Lastname='test', Phone='9807213456', email='test@test.com');
    insert le;
   
    le.email = null;
     le.phone = null;

        update le;

                 
    }
}

Please mark this as Best Answer if it helps!
 
DeveloperDeveloper
Hi Saurabh ,
Thank you for given repley, the code covarege is only 75%. i want 100%
DeveloperDeveloper
Hi Nabeel,
Thank you for giving reply,
 it's fine working  100% code covarage.
 
Leo10Leo10
@isTest

private class phonevalidation_Test{ 
	static testMethod void testMethods(){
		list<Lead> leads = new list<Lead>();
		Lead lead1 = new Lead( Lastname='Demo1', Phone='111111111', email='test@gmail.com');
		leads.add(lead1);
		Lead lead2 = new Lead( Lastname='Demo2', Phone='', email='');
		leads.add(lead2);
		insert leads;
	}
}

By mistake, I deleted my answer. Please mark this as Best Answer if it helps!
This was selected as the best answer
Leo10Leo10
Thank you Gopal :)