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

Test method - Help


i dont know how to start, in writing test method for the below controller. Can anyone help me?


This is my controller:


public with sharing class picklistTest
    Map<String, String> mapSelectListValues = new Map<String, String>();
    public String selectedVal {get;set;}
    public String selectedLab {get;set;}
    public List<SelectOption> getOptions1()
        List<SelectOption> retVal = new List<SelectOption>();
        List<AggregateResult> result = [Select Id, type, Number, CALENDAR_YEAR(StartDate)s from Period];
        retVal.add(new SelectOption('','-- Choose a Group --'));        
        for(AggregateResult a : result)
          String c  = String.valueOf(a.get('type'));
          integer v = integer.valueOf(a.get('Number'));
          integer s = integer.valueOf(a.get('s'));
          retVal.add(new SelectOption(a.Id,c+' '+v+' - '+s));                 
        for(Selectoption s: retVal)
            mapSelectListValues.put(s.getValue(), s.getLabel());
        return retVal;    

   public List<PieWedgeData> getPieData()
        List<PieWedgeData> data = new List<PieWedgeData>();
        for(AggregateResult ar :[Select Fiscal_Year(StartDate)fy, Fiscal_Quarter(StartDate)fq from Period where Id =: selectedVal group by Fiscal_Year(StartDate),Fiscal_Quarter(StartDate)])
           integer year = integer.valueOf(ar.get('fy'));
           integer quat = integer.valueOf(ar.get('fq'));
           for(AggregateResult ar1 : [Select Count(Amount)tcnt from Opportunity where FiscalYear =: year and FiscalQuarter =: quat])
                Integer cnt = integer.valueOf(ar1.get('tcnt'));
                data.add(new PieWedgeData('Created Opps',cnt));
           for(AggregateResult ar2 : [Select Count(Amount)tcnt1 from Opportunity where FiscalYear =: year and FiscalQuarter =: quat and StageName = 'Closed Won'])
                Integer cnt1 = integer.valueOf(ar2.get('tcnt1'));
                data.add(new PieWedgeData('Won Opps',cnt1));
           for(AggregateResult ar3 : [Select Count(Amount)tcnt2 from Opportunity where FiscalYear =: year and FiscalQuarter =: quat and StageName = 'Closed Lost'])
                Integer cnt2 = integer.valueOf(ar3.get('tcnt2'));
                data.add(new PieWedgeData('Lost Opps',cnt2));
       return data;

public class PieWedgeData

        public String name { get; set; }
        public Integer data { get; set; }

        public PieWedgeData(String name, Integer data)
   = name;
   = data;



and following is my vf page,


<apex:page controller="picklistTest" showHeader="false" >
  <apex:form >
               <apex:pageBlock title="Select Range:">
                   <apex:actionRegion >  
                       <apex:selectList value="{!selectedVal}" size="1" multiselect="false">
                       <apex:selectOptions value="{!options1}"/>
                       <apex:actionSupport event="onchange" action="{!showValue}" rerender="profile,pipeline" />


                <apex:chart data="{!pieData}" width="500" height="215">
                <apex:axis type="Category" position="left" fields="name" grid="false" gridFill="false"/>
                <apex:axis type="Numeric" position="bottom" fields="data" title="Count" minimum="0">
                <apex:chartLabel rotate="315"/>
                <apex:barSeries orientation="horizontal" axis="bottom" xField="data" yField="name"/>



Please help me to achieve the minimum code coverage. Its urgent.












Here is your Test class method.


public class TestpicklistTest{
    Private Static testmethod void TestpicklistTest(){
        picklistTest objpicklistTest = new picklistTest();
        period objperiod = new period();
        objperiod.type = 'Test type';
        objperiod.Number = '123456';
        objperiod.StartDate =;        
        insert objperiod;
        objpicklistTest.selectedVal =;


important :

Hit Kudos if this provides you with useful information and if this is what you where looking for then please mark it as a solution for other benefits.


Hitesh Patel


hey thanks for your reply,

I will try this and get back to you as soon as posible.





have you got the solution?