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
Martina OmpusungguMartina Ompusunggu 

test class - help me to get 100%

Here is my task controller:
newTaskController
and here is my test class:

@isTest
private class newTaskTest{

    static testMethod void createTask() 
    {
        Lead lead = new Lead(LastName='febrian',company='febrian test');
        insert lead;
        Account acc = new Account(Name='test');
        insert acc;
        Opportunity opp = new Opportunity(AccountId=acc.Id,Name='test opp',StageName = 'Prospecting',CloseDate = date.today());
        insert opp;
        
        PageReference pR = Page.newTaskContactLayout;
        Test.setCurrentPage(pR);
        
        ApexPages.Standardcontroller sc = new ApexPages.Standardcontroller(lead);
        ApexPages.currentPage().getParameters().put('Id',lead.id);
        
        newTaskController ntc = new newTaskController(sc);
        
        Task tsk = new Task(Status='Completed',Subject='Reached Call',Type='Reached Call',Description='test',ActivityDate=System.today(),whoId =lead.id);
        insert tsk;
        ntc.saveTask();
        
        ApexPages.Standardcontroller sc2 = new ApexPages.Standardcontroller(opp);
        ApexPages.currentPage().getParameters().put('Id',opp.id);
        
        newTaskController ntc2 = new newTaskController(sc2);
        
        Task tsk2 = new Task(Status='Completed',Subject='Reached Call',Type='Reached Call',Description='test',ActivityDate=System.today(),whatId =lead.id);
        insert tsk2;
        ntc2.saveTask();
        
        system.assertEquals(null, pR);
    }  
    static testMethod void updateTimestamp(){
        //PageReference pr = Page.newTaskContactLayout;
        //Test.setCurrentPage(pr);
        Account acc = new Account();
        acc.Name = 'Test Account';
        insert acc;
        
        Contact cont = new Contact();
        cont.AccountId = acc.Id;
        cont.FirstName = 'FirstName';
        cont.LastName = 'LastName';
        cont.Email='flname@email.com';
        insert cont;
        
        Opportunity opp = new Opportunity(AccountId = acc.Id,Name='test opp',StageName = 'Prospecting',CloseDate = date.today());
        insert opp;
        
        test.startTest();
        //Test.setCurrentPageReference(pr);
        test.setCurrentPage(Page.newTaskContactLayout);
        
        ApexPages.StandardController sc2 = new ApexPages.StandardController(opp);
        //ApexPages.StandardSetController sc2 = new ApexPages.StandardSetController(opp);
        //sc2.setSelected(opp);
        ApexPages.currentPage().getParameters().put('Id',opp.id);
        
        newTaskController ntc2 = new newTaskController(sc2);
        cont.Follow_Up_Timestamp__c = System.NOW();
        update cont;
        ntc2.callQueue();
        
        ApexPages.StandardController sc3 = new ApexPages.StandardController(cont);
        ApexPages.currentPage().getParameters().put('Id',cont.id);
        
        newTaskController ntc3 = new newTaskController(sc3);
        cont.Follow_Up_Timestamp__c = System.now();
        update cont;
        ntc3.callQueue();
        //system.assertEquals(null, pR);  
    }
}

after run test, I got code coverage 80%. Could anybody give me solutions to resolve this? I need 100% coverage asap. Thank you.

Rahul KumarRahul Kumar (Salesforce Developers) 
Hi Martina Ompusunggu, I hope it will be helpful.

Please mark it as best answer if the information is informative.

Best Regards
Rahul Kumar