0

I am trying to fetch the pick list value from custom settings, i am getting Unknown property 'TestList' Error is in expression '{!CTest List}' in component in page this is my method for pick list field What i am missing here ?

 public String TestReason {get; set;}
  public List<SelectOption> TestList(){
        List<SelectOption> options = new List<SelectOption>();
        options.add(new SelectOption('','--None--'));
        //List<Test_Reason__c> TestReasonValue = Test_Reason__c.getall().values();
      for(Test_Reason__c TestReasonValue :Test_Reason__c.getall().values()){
      options.add(new SelectOption(TestReasonValue.Name , TestReasonValue.Test_Reason__c));}
        return options;
    } 
1
  • Please post your vf page code. Sep 6, 2019 at 10:12

2 Answers 2

0

thanks for your response i resolved above issue by adding get ,,,, here is my working code

  public String TestReason {get; set;}
  public List<SelectOption> TestList{get
  {
      List<SelectOption> options = new List<SelectOption>();
      options.add(new SelectOption('','--None--'));
      //List<Test_Reason__c> TestReasonValue = Test_Reason__c.getall().values();
      for(Test_Reason__c TestReasonValue :Test_Reason__c.getall().values()){
          options.add(new SelectOption(TestReasonValue.Name , TestReasonValue.Test_Reason__c));}
          return options;
  } 
0

Priya, here's a better pattern to use for populating selectLists as you only need to populate it once (lazy load pattern - worth learning). Note also variable names for clarity (and I renamed your custom setting)

public String selectedReason {get; set;}
public List<SelectOption> reasonOptions {
  get {
    if (reasonOptions == null) {
      reasonOptions = new List<SelectOption> {new SelectOption('','--None--')};
      for (Reason__c reasonOption: Reason__c.getAll().values()) {
         reasonOptions.add(new SelectOption(reasonOption.Name,reasonOption.Reason__c));
      }
    }
    return reasonOptions;
  } private set;
}

then the VF page looks clearer

 <apex:selectList value="{!selectedReason}">
   <apex:selectOptions value="{!reasonOptions}"/>
 </apex:selectList>

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .