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
Jim Shorkey 6Jim Shorkey 6 

Apex Testing

I am trying to learn Apex coding and I am unable to figure out how to write a test class for the code below:

public class FilterTasksCall {
   
    public Task[] tasks {get; private set;}
   
    public FilterTasksCall() {
        Id id = (Id) ApexPages.currentPage().getParameters().get('id');
         tasks = [Select
                    Who.Id,
                    Who.Name,
                    Id,
                    Subject,
                    What.Name,
                    ActivityDate,
                    Owner.Name,
                    Status,
                    LastModifiedDate
                    From Task
                    Where Subject Like '%Call%' and Who.Id=:ApexPages.currentPage().getParameters().get('id')];
    }

}

Thank you and your help is very much appreciated,
Jim
Best Answer chosen by Jim Shorkey 6
Rupal KumarRupal Kumar
Hi, 
Try this code cover this class-
 
@isTest
private class FilterTasksCallcls {

static testMethod void myUnitTest() {

    Task tk = new Task();
    tk.Subject= 'test1';
    tk.Status= 'Qualified';
    tk.ActivityDate= Date.Today();
   
    insert tk;
    
     Test.StartTest(); 
      ApexPages.StandardController sc = new ApexPages.StandardController(tk);
      FilterTasksCall filtc= new FilterTasksCall ();

     Test.StopTest();
    
    }
  }

Thanks
Rupal kumar
http://mirketa.com

All Answers

Rupal KumarRupal Kumar
Hi, 
Try this code cover this class-
 
@isTest
private class FilterTasksCallcls {

static testMethod void myUnitTest() {

    Task tk = new Task();
    tk.Subject= 'test1';
    tk.Status= 'Qualified';
    tk.ActivityDate= Date.Today();
   
    insert tk;
    
     Test.StartTest(); 
      ApexPages.StandardController sc = new ApexPages.StandardController(tk);
      FilterTasksCall filtc= new FilterTasksCall ();

     Test.StopTest();
    
    }
  }

Thanks
Rupal kumar
http://mirketa.com
This was selected as the best answer
Jim Shorkey 6Jim Shorkey 6
Rupal,

Thank you so much.  This worked perfectly.

Jim