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
Rest API IntegrationRest API Integration 

Apex Code not working properly


I have created a task in my org with subject "Email Task"

I have written apex code as

    public class  TaskInfoDAOClass
    {
       public static List<Task> queryTaskInfo ()
        {
    integer count = [SELECT count() FROM Task];
    System.debug('Row Count :'+ count);
     List<Task> tasks= [SELECT Task.Id,Task.AccountId,Task.Status,Task.Account.Name FROM Task where Task.Subject='Email Task'];
      return tasks;     
      }
    }

I have created one test class to test apex code as

    @isTest
    public class TestTaskInfoDAO
    {
     public static testMethod void testQueryTaskInfo()
     {
    List<Task> tasks = TaskInfoDAOClass.queryTaskInfo();
     System.debug ('this is a debug statement');

    for (Task t : tasks)
    {
     System.debug ('Status '+ t.Status);
      System.debug ('Account name '+ t.Account.Name);

     }
    }
    }

when I run this test I am getting 0 as ROW count. please refer apex.log file

    24.0 APEX_CODE,FINE;APEX_PROFILING,FINE;DB,INFO;VALIDATION,INFO;WORKFLOW,FINEST
    23:48:30.100 (100678000)|EXECUTION_STARTED
    23:48:30.100 (100722000)|CODE_UNIT_STARTED|[EXTERNAL]|01p90000000k5Qw|TestTaskInfoDAO.testQueryTaskInfo
    23:48:30.101 (101272000)|METHOD_ENTRY|[2]|01p90000000k5Qw|TestTaskInfoDAO.TestTaskInfoDAO()
    23:48:30.101 (101414000)|METHOD_EXIT|[2]|TestTaskInfoDAO
    23:48:30.101 (101494000)|METHOD_ENTRY|[1]|01p90000000k5Qr|TaskInfoDAOClass.TaskInfoDAOClass()
    23:48:30.101 (101513000)|METHOD_EXIT|[1]|TaskInfoDAOClass
    23:48:30.101 (101782000)|METHOD_ENTRY|[6]|01p90000000k5Qr|TaskInfoDAOClass.queryTaskInfo()
    23:48:30.102 (102176000)|SOQL_EXECUTE_BEGIN|[5]|Aggregations:0|select count() from Task
    23:48:30.106 (106893000)|SOQL_EXECUTE_END|[5]|Rows:0
    23:48:30.106 (106965000)|SYSTEM_METHOD_ENTRY|[6]|String.valueOf(Object)
    23:48:30.107 (107012000)|SYSTEM_METHOD_EXIT|[6]|String.valueOf(Object)
    23:48:30.107 (107032000)|SYSTEM_METHOD_ENTRY|[6]|System.debug(ANY)
    23:48:30.107 (107040000)|USER_DEBUG|[6]|DEBUG|Row Count :0
    23:48:30.107 (107047000)|SYSTEM_METHOD_EXIT|[6]|System.debug(ANY)
    23:48:30.107 (107385000)|SOQL_EXECUTE_BEGIN|[9]|Aggregations:0|select Task.Id, Task.AccountId, Task.Status, Task.Account.Name from Task where Task.Subject = 'Email Task'
    23:48:30.109 (109847000)|SOQL_EXECUTE_END|[9]|Rows:0
    23:48:30.109 (109930000)|METHOD_EXIT|[6]|01p90000000k5Qr|TaskInfoDAOClass.queryTaskInfo()
    23:48:30.110 (110074000)|USER_DEBUG|[7]|DEBUG|this is a debug statement
    23:48:30.789 (111361000)|CUMULATIVE_LIMIT_USAGE
    23:48:30.789|LIMIT_USAGE_FOR_NS|(default)|
      Number of SOQL queries: 2 out of 100
      Number of query rows: 0 out of 50000
      Number of SOSL queries: 0 out of 20
      Number of DML statements: 0 out of 150
      Number of DML rows: 0 out of 10000
      Number of script statements: 7 out of 200000
      Maximum heap size: 0 out of 6000000
      Number of callouts: 0 out of 10
      Number of Email Invocations: 0 out of 10
      Number of fields describes: 0 out of 100
      Number of record type describes: 0 out of 100
      Number of child relationships describes: 0 out of 100
      Number of picklist describes: 0 out of 100
      Number of future calls: 0 out of 10

    23:48:30.789|TOTAL_EMAIL_RECIPIENTS_QUEUED|0
    23:48:30.789|STATIC_VARIABLE_LIST|
      double:MAX_VALUE:0
      long:serialVersionUID:0
        int:MAX_EXPONENT:0
        int:MIN_EXPONENT:0
        Boolean:TRUE:0
        long:serialVersionUID:0
        double:POSITIVE_INFINITY:0
        double:MIN_NORMAL:0
        double:MIN_VALUE:0
        Boolean:FALSE:0
        int:SIZE:0
        char[]:DigitOnes:0
        int[]:sizeTable:0
        char[]:DigitTens:0
        double:NaN:0
        int:MAX_VALUE:0
        char[]:digits:0
        long:serialVersionUID:0
        double:NEGATIVE_INFINITY:0
        int:MIN_VALUE:0
        int:SIZE:0

    23:48:30.789|CUMULATIVE_LIMIT_USAGE_END

    23:48:30.111 (111444000)|CODE_UNIT_FINISHED|TestTaskInfoDAO.testQueryTaskInfo
    23:48:30.111 (111452000)|EXECUTION_FINISHED
    23:48:30.999|CUMULATIVE_PROFILING_BEGIN
    23:48:30.999|CUMULATIVE_PROFILING|SOQL operations|
      Class.TaskInfoDAOClass.queryTaskInfo: line 5, column 1: [SELECT count() FROM Task]: executed 1 time in 5 ms
      Class.TaskInfoDAOClass.queryTaskInfo: line 9, column 1: [SELECT Task.Id,Task.AccountId,Task.Status,Task.Account.Name FROM Task where Task.Subject='Email Task']: executed 1 time in 3 ms

    23:48:30.999|CUMULATIVE_PROFILING|No profiling information for SOSL operations
    23:48:30.999|CUMULATIVE_PROFILING|No profiling information for DML operations
    23:48:30.999|CUMULATIVE_PROFILING|method invocations|
      External entry point: public static testMethod void testQueryTaskInfo(): executed 1 time in 11 ms
      Class.TestTaskInfoDAO.testQueryTaskInfo: line 6, column 1: public static LIST<Task> queryTaskInfo(): executed 1 time in 8 ms
      Class.TestTaskInfoDAO.testQueryTaskInfo: line 9, column 1: global object iterator(): executed 2 times in 1 ms
      Class.TaskInfoDAOClass.queryTaskInfo: line 6, column 1: global public static String valueOf(Object): executed 2 times in 0 ms
      Class.TestTaskInfoDAO.testQueryTaskInfo: line 7, column 1: global public static void debug(ANY): executed 1 time in 0 ms

    23:48:30.999|CUMULATIVE_PROFILING_END

Why I am getting 0 ROW COUNT ?

bob_buzzardbob_buzzard

You aren't creating any tasks as part of your test that I can see, and if your apex is at API version 24 you won't be able to see any of the existing org data.  Best practice for this is to insert a task as part of your test.