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
soma s 6soma s 6 

why trigger code covergae always shows 0%

hi all
       I have written the below after update trigger on task and also test code, my test code run success but code coverage shows zero percentage could please help me 

Salesforce - Unlimited Editiontrigger Trigtask on Task(after update) 
{
Set<String> accids = new Set<String>();


    Set<String> taskaccid= new Set<String>();
       Set<String> acountph= new Set<String>();
           string taskacno ;
    
       for(task acc: Trigger.new) 
    {
         List<Task> accListS = [select accountid from task where accountid  IN :accids  AND CallDisposition LIKE '%Lead%'];
            if(accListS != null && !accListS .isEmpty()) 
            {
                taskacno = acc.accountid;
             taskaccid.add(acc.accountid);
           }
           }

      List<Account> accphone = [Select Id,IsPersonAccount,StrPhr_Do_Not_Call_Group_Practice__c, PersonDoNotCall,StrPhr_Lead_Qualified__c  from Account where Phone IN: taskaccid];       
      if(accphone != null && !accphone .isEmpty()) 
            {
             for(Account accph: accphone ) 
{
                              acountph.add(accph.Phone);
           }
    }
   
    if(!acountph.isEmpty()) 
    {
        List<Account> accList = [Select Id,IsPersonAccount,StrPhr_Do_Not_Call_Group_Practice__c, PersonDoNotCall,StrPhr_Lead_Qualified__c  from Account where Phone IN: acountph];        {
            for(Account acc: accList) 
            {
               if ( acc.IsPersonAccount == true && acc.StrPhr_Do_Not_Call_Group_Practice__c == False && acc.ID ==taskacno )  
            
                {
                acc.StrPhr_Do_Not_Call_Group_Practice__c=True;
                 //acc.PersonDoNotCall = True;

                                   }
                if ( acc.IsPersonAccount == true && acc.StrPhr_Do_Not_Call_Group_Practice__c == False && acc.ID !=taskacno ) 
                {
                acc.StrPhr_Do_Not_Call_Group_Practice__c=True;
                 acc.PersonDoNotCall = True;

                                   }

                                   
                         }
            update accList;
        }
    }
}


test code 

Salesforce - Unlimited Edition@isTest 
public class Tritasktest{

    static testMethod void testMethodOne() 
    {
       
          Account accone = new Account();
        accone .Name='Test Account Two';
        accone .Phone='555555';
        accone .StrPhr_Do_Not_Call_Group_Practice__c = false;
        insert accone ;
Task taskone= new task();
                         taskone.whatid= accone .id;
                         taskone.CallDisposition ='Leadrep';
                        // taskone.what=accTwo.id;
             insert taskone;
        Account acctwo = new Account();
        accTwo.Name='Test Account Two';
        acctwo.Phone='555555';
        accTwo.StrPhr_Do_Not_Call_Group_Practice__c = false;
        insert accTwo;
        
         Task tasktwo= new task();
                         tasktwo.whatid= acctwo .id;
                         tasktwo.CallDisposition ='Leadrep';
                        // taskone.what=accTwo.id;
             insert tasktwo;             
                
    task acc = [select Id,accountid, CallDisposition,Account_Ph_No__c from task where whatId =: accone.Id LIMIT 1];
   // Account acc = [select Id, StrPhr_Do_Not_Call_Group_Practice__c from Account where Id =: accTwo.Id LIMIT 1];
   //system.assertequals([select Account_Ph_No__c from task where whatId =:accone.Id],'555555');
      
        System.assertEquals(acc.accountid,accone.id );
//System.assertEquals(acc.name, ‘testName’);

        accTwo.StrPhr_Do_Not_Call_Group_Practice__c = true;
        update accTwo;


//List<Task> accListS = [select accountid from task where accountid  IN :accids  AND CallDisposition LIKE '%Lead%'];

    }
    static testMethod void testMethodTwo() 
    {
        Account accOne = new Account();
        accOne.Name='Test Account One';
        accOne.StrPhr_Do_Not_Call_Group_Practice__c = false;
        accOne.Phone ='5555555555';
        insert accOne;
         

        Account accTwo = new Account();
        accTwo.Name='Test Account Two';
        accTwo.StrPhr_Lead_Qualified__c = false;
        accTwo.Phone ='5555555555';
        accTwo.StrPhr_Do_Not_Call_Group_Practice__c = false;
        accTwo.PersonDoNotCall = false;


        insert accTwo;

        accTwo.StrPhr_Lead_Qualified__c = True;
         accTwo.StrPhr_Do_Not_Call_Group_Practice__c = True;
         //accTwo.PersonDoNotCall = True;

          

        update accTwo;

    }



}
soma s 6soma s 6
Thanks for your update now after update the test class the code coverage is 44% , i couldnt get why its only 44% given below trigger code and test code . is whatid and accountid is same in task?, please note that am using personaccount and activity in task

Salesforce - Unlimited Editiontrigger Trigtask on Task(after update) 
{
Set<String> accids = new Set<String>();


    Set<String> taskaccid= new Set<String>();
       Set<String> acountph= new Set<String>();
           string taskacno ;
    
       for(task acc: Trigger.new) 
    {
         List<Task> accListS = [select accountid from task where accountid  IN :accids  AND CallDisposition LIKE '%Lead%'];
            if(accListS != null && !accListS .isEmpty()) 
            {
                taskacno = acc.whatid;
             taskaccid.add(acc.whatid);
           }
           }

      List<Account> accphone = [Select Id,IsPersonAccount,StrPhr_Do_Not_Call_Group_Practice__c, PersonDoNotCall,StrPhr_Lead_Qualified__c  from Account where Phone IN: taskaccid];       
      if(accphone != null && !accphone .isEmpty()) 
            {
             for(Account accph: accphone ) 
{
                              acountph.add(accph.Phone);
           }
    }
   
    if(!acountph.isEmpty()) 
    {
        List<Account> accList = [Select Id,IsPersonAccount,StrPhr_Do_Not_Call_Group_Practice__c, PersonDoNotCall,StrPhr_Lead_Qualified__c  from Account where Phone IN: acountph];        {
            for(Account acc: accList) 
            {
               if ( acc.IsPersonAccount == true && acc.StrPhr_Do_Not_Call_Group_Practice__c == False && acc.ID ==taskacno )  
            
                {
                acc.StrPhr_Do_Not_Call_Group_Practice__c=True;
                 //acc.PersonDoNotCall = True;

                                   }
                if ( acc.IsPersonAccount == true && acc.StrPhr_Do_Not_Call_Group_Practice__c == False && acc.ID !=taskacno ) 
                {
                acc.StrPhr_Do_Not_Call_Group_Practice__c=True;
                 acc.PersonDoNotCall = True;

                                   }

                                   
                         }
            update accList;
        }
    }
}

test code

@isTest 
public class Tritasktest{

    static testMethod void testMethodOne() 
    {
       
          Account accone = new Account();
        accone .Name='Test Account Two';
        accone .Phone='555555';
        accone .StrPhr_Do_Not_Call_Group_Practice__c = false;
        insert accone ;
        accone .Phone='555555';
                accone .StrPhr_Do_Not_Call_Group_Practice__c = true;
        update accone ;

        Task taskone= new task();
         taskone.whatid= accone .id;
         taskone.CallDisposition ='Leadrep';
                                    insert taskone;
        Account acctwo = new Account();
        accTwo.Name='Test Account Two';
        acctwo.Phone='555555';
        accTwo.StrPhr_Do_Not_Call_Group_Practice__c = false;
        insert accTwo;
        acctwo.Phone='555555';
                accTwo.StrPhr_Do_Not_Call_Group_Practice__c = true;
        update accTwo;

         Task tasktwo= new task();
         tasktwo.whatid= acctwo .id;
         tasktwo.CallDisposition ='Leadrep';
         insert tasktwo;   
         tasktwo.whatid= acctwo.id;
         Task t=[SELECT whatid,CallDisposition FROM Task WHERE whatid=:acctwo.id].get(0);

         tasktwo.CallDisposition='Lead';
          update tasktwo;     
          
              Account acc1 = [select Id,isPersonAccount, StrPhr_Do_Not_Call_Group_Practice__c,phone from Account where Id =: accTwo.Id LIMIT 1];
        System.assertEquals(true, acc1.StrPhr_Do_Not_Call_Group_Practice__c);  
        System.assertEquals('555555', acc1.Phone);  
        
    task acc = [select Id,whatid,accountid, CallDisposition,Account_Ph_No__c from task where whatId =: accone.Id LIMIT 1];
  
      
        System.assertEquals(acc.whatid,accone.id );
         
        



    }
    static testMethod void testMethodTwo() 
    {
        Account accOne = new Account();
        accOne.Name='Test Account One';
        accOne.StrPhr_Do_Not_Call_Group_Practice__c = false;
        accOne.Phone ='5555555555';
        insert accOne;
         

        Account accTwo = new Account();
        accTwo.Name='Test Account Two';
        accTwo.StrPhr_Lead_Qualified__c = false;
        accTwo.Phone ='5555555555';
        accTwo.StrPhr_Do_Not_Call_Group_Practice__c = false;
        accTwo.PersonDoNotCall = false;


        insert accTwo;

        accTwo.StrPhr_Lead_Qualified__c = True;
         accTwo.Phone ='5555555555';
         accTwo.StrPhr_Do_Not_Call_Group_Practice__c = True;
        
          

        update accTwo;

    }



}
soma s 6soma s 6
Thanks a lot my code coverage happen 44% but it fails  to cover the below lines 
      taskacno = acc.whatid;
             taskaccid.add(acc.whatid);

            for(Accounfor(Account accph: accphone ) 
{
                              acountph.add(accph.Phone)

if(!acountph.isEmpty()
acc.StrPhr_Do_Not_Call_Group_Practice__c=True;
soma s 6soma s 6
Bala could you please explain, i couldnt get you 
already in my test class am inserting task.calldisposition ='Leadrep' 
soma s 6soma s 6
bala thanks for your help implemeneted your suggestion and now its 88% code coverage