+ Start a Discussion
ManjusrinuManjusrinu 

test classes for contact duplicate preventor

Hi
I need a test class for the below requirement 

At the time of contact insertion/updation, check with the email field, if email already exist in database then throw an error .
my Trigger name:contactDuplicatePreventer
sachinarorasfsachinarorasf
Hi Meka,

If you are checking the contact's email field while inserting or updating a contact in apex then you just need to insert or update the contact record in your test class like below:
@isTest
private class TestDuplicateContact{

@isTest
public static void insertContact(){

Contact conobj =  new Contact();
conobj.LastName = 'Test';
conobj.Email = 'abc@xyz.com';

Test.startTest();
insert conobj;
Test.stopTest();
}
}

Please mark it as best answer if you find it helpful.

Thanks
Sachin Arora
ManjusrinuManjusrinu
Hi, the following code is showing only 61percent of code coverage can i please know how to have 100 percent code coverage