function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
kirankumarreddy punurukirankumarreddy punuru 

how to cover this line in test class

Hi ,
I am having one condtion in trigger like :
if(trigger.isUpdate && trigger.isAfter)
{
code;
}
 how to satisfy the above if condition to cover the code inside if condition .

Regards,
Kiran
 
Best Answer chosen by kirankumarreddy punuru
AshlekhAshlekh
Hi,

Just write a test class and create a record in test class and then update that reocrd.

For eg:
 
@isTest
Private class TestClassAccountTrigger{

static testMethod void myTest(){
   Account a = new Account(name='Test');
   insert a;
   Test.StartTest();
   a.name = 'Test 2';
   update a;
   Test.StopTest();
 }
}

-Thanks
Ashlekh Gera

All Answers

AshlekhAshlekh
Hi,

Just write a test class and create a record in test class and then update that reocrd.

For eg:
 
@isTest
Private class TestClassAccountTrigger{

static testMethod void myTest(){
   Account a = new Account(name='Test');
   insert a;
   Test.StartTest();
   a.name = 'Test 2';
   update a;
   Test.StopTest();
 }
}

-Thanks
Ashlekh Gera
This was selected as the best answer
kirankumarreddy punurukirankumarreddy punuru
Thanks Ashlekh Gera