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
karthic sankar 9karthic sankar 9 

Attempt to de-reference a null object in Test Class

HI Team,

Please let me how to get rid of this error,

My Controller method.

public void Init()
    {
        System.debug('Test method called');
         strText = ApexPages.currentPage().getParameters().get('str');
        //strText1 = ApexPages.currentPage().getParameters().get('str1');
        System.debug(strText);
        list<String> strTextVal = strText.split(',');
        System.debug(strTextVal[0]);
        System.debug(strTextVal[1]);
        queryData = [select RadioFeild__c, During_Week_Availability__c,Status__c,Reason_Comments__c,Reason_comments_for_Recent_Rejection__c, During_Week_OtherWorkFile__c, During_Week_OtherWorkEst__c,During_Week_FileSelection__c,During_Week__c,During_Week_Debreifs__c,During_Week_Core__c, Reason_Rejection__c, Other3_core__c, Total_Total_time__c, CommentsAvailability__c, Other1Title__c, Other2Title__c, Picklist__c, Date_QAAM__c, Week_Start_Date__c,
                                                  Availability__c, ReasonAvailability__c, Work_Hours__c, Pre_Vet_Reviews__c, BAU_File_Reviews__c, Debriefs__c,
                                                  File_Selection__c, Other_work__c, Other_work_Estimate__c, Total_Work_Time__c, Team_Meeting__c, Huddle__c, 
                                                  Quarterly_Updates__c, Governance_Forums__c, Performance_Reviews__c, Tea_Breaks__c, CPD_e_Learning_Maintenance__c, 
                                                  Coaching__c, PD_Days__c, One_on_Ones__c, Weekly_Tracker_preparation__c, Business_Communications__c, 
                                                  Other__c, Other1__c, Other2__c, Project_Time__c, Other_Time__c, Project_Time_Description__c, 
                                                  Other_Time_Description__c, Shrinkage_time__c, Available_Time__c, Availability_Checking__c, id, Week__C 
                                                  from QAAM_Weekly_Planner__c where Week__C =: strTextVal[0] and CreatedBy.Name =:strTextVal[1]];
        list<String> weekDataStatic = new list<String>{'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday'};
            integer i=0;
            
}

My test class

 static testmethod void Init()
    {
        a init = new a();
        init.strText = 'abc,abc';

        init.queryData = [select CommentsAvailability__c, Other1Title__c, Other2Title__c, Picklist__c, 
                                                  Date_QAAM__c, Week_Start_Date__c, Availability__c, ReasonAvailability__c, 
                                                  Work_Hours__c, Pre_Vet_Reviews__c, BAU_File_Reviews__c, Debriefs__c, File_Selection__c,
                                                  Other_work__c, Other_work_Estimate__c, Total_Work_Time__c, Team_Meeting__c, Huddle__c,
                                                  Quarterly_Updates__c, Governance_Forums__c, Performance_Reviews__c, Tea_Breaks__c, 
                                                  CPD_e_Learning_Maintenance__c, Coaching__c, PD_Days__c, One_on_Ones__c, 
                                                  Weekly_Tracker_preparation__c, Business_Communications__c, Other__c, Other1__c, 
                                                  Other2__c, Project_Time__c, Other_Time__c, Project_Time_Description__c, 
                                                  Other_Time_Description__c, Shrinkage_time__c, Available_Time__c, 
                                                  Availability_Checking__c, id, Week__C from QAAM_Weekly_Planner__c];

test.startTest();
        init.Init();
        test.stopTest();

}

Error:
System.NullPointerException: Attempt to de-reference a null object
goabhigogoabhigo
Test class doesn't have org's data directly, if you have not specified @SeeAllData=True (refer - SeeAllData (https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_testing_seealldata_using.htm)). Ideally you should not access/query org's data, rather you should create test records inside test classes (refer - Test Data (https://trailhead.salesforce.com/content/learn/modules/apex_testing/apex_testing_data)).
Also, add e.getStackTraceString(), to your debug statement to get more details.

--
goabhigo