+ Start a Discussion
karthic sankar 9karthic sankar 9 

please help me in writing apex test

HI Everyone.


public class ViewQAAMController {
public ViewQAAMController()
String weekData = '20/07/2020 - 24/07/2020';
        list<String> lstSplitDate1 = new list<String>();
        lstSplitDate1 = weekData.split(' - ');
        strText = ApexPages.currentPage().getParameters().get('str');
        System.debug('inside method '+ApexPages.currentPage().getParameters().get('weekValue'));
        System.debug('inside method value '+test);
        System.debug('inside method value for strText'+strText);
        //for(String s : lstSplitDate1)
            //System.debug('The date is '+s);
        list<QAAM_Weekly_Planner__c> 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 where Week__C =: strText];
        System.debug('The query value is: '+queryData);
        list<String> weekDataStatic = new list<String>{'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday'};
            integer i=0;
        for(QAAM_Weekly_Planner__c q : queryData)
             dateValues = q.Week_Start_Date__c;
            AvailabilityMap.put(weekDataStatic[i], q.Availability__c);



Please help me in wriritng a testclass guys. I am fully stuck up.

Karthic Sankar V P
David Zhu 🔥David Zhu 🔥
You may try this:
public static testmethod void test()
	QAAM_Weekly_Planner__c  weeklyPlanner = new QAAM_Weekly_Planner__c ();
        weeklyPlanner.Week__c = 'something';
	weeklyPlanner.otherfield1  = '....';
	weeklyPlanner.otherfield2  = '....';
	weeklyPlanner.otherfield3  = '....';

	Test.setCurrentPage(Page.myVFPage);   //replace myVFPage with the real page name.
	ApexPages.currentPage().getParameters().put('str','something');   //value is the same as the one assigned to week__c;

	ViewQAAMController controller = new ViewQAAMController();


karthic sankar 9karthic sankar 9
Thank you