1

I have one controller and one VF page.I am getting error saying "Unknown property 'Multipicklist.getPicklistValues'" for VF page.Dont know why it is.

Controller:

     global class Multipicklist {

    global list<SelectOption> picklistValues{get;set;}
    SObject Account;
    String Dummy='Dummy__c';
    global  Multipicklist(){

  list<SelectOption> picklistValues = new list<SelectOption>();
  // Get the object type of the SObject.
  Schema.sObjectType objType = Account.getSObjectType(); 
  // Describe the SObject using its object type.
  Schema.DescribeSObjectResult objDescribe = objType.getDescribe();       
  // Get a map of fields for the SObject
  map<String, Schema.SObjectField> fieldMap = objDescribe.fields.getMap(); 
  // Get the list of picklist values for this field.
  list<Schema.PicklistEntry> values =
     fieldMap.get(Dummy).getDescribe().getPickListValues();
        System.debug('value of values :::'+values);
  // Add these values to the selectoption list.
  for (Schema.PicklistEntry a : values)
  { 
     picklistValues.add(new SelectOption(a.getLabel(), a.getValue())); 
      System.debug('value of picklist added :::'+picklistValues);
  }

 }
}

VF Page:

    <apex:page controller="Multipicklist" >
    <apex:form>
        <apex:pageblock>
    <apex:selectCheckboxes border="3">
    <apex:selectOptions value="{!PicklistValues}"></apex:selectOptions>
</apex:selectCheckboxes>
            </apex:pageblock>
        </apex:form>
</apex:page>

3 Answers 3

1

When you define a method with get as the prefix you are defining a getter method so you do not use the get when calling it from the page so change to:

<apex:selectOptions value="{!PicklistValues}"></apex:selectOptions>

You also need to pass the parameters for the method so they get set as you are not doing that in you vf page currently

5
  • Still getting below error on change to above. Error:Unknown property 'Multipicklist.PicklistValues'
    – Jack vardy
    Nov 5, 2015 at 5:17
  • Could you please let me know how to pass the parameters for the method so they get set
    – Jack vardy
    Nov 5, 2015 at 5:20
  • 1
    You need to remove the parameters from the method signature in you class. Then assign them to class properties instead
    – Eric
    Nov 5, 2015 at 5:22
  • Now getting error "Attempt to de-reference a null object " on opening VF page using below link.I have edited code for my controller as well as VF page above c.ap2.visual.force.com/apex/Test13
    – Jack vardy
    Nov 5, 2015 at 5:31
  • Well, you are not setting the values anywhere before you attempt to use them.
    – Eric
    Nov 5, 2015 at 5:34
0

Use the below code, execute your method inside the constructor and populate the options, then refer it inside your visualForce tag <apex:selectOptions value="{!options}"></apex:selectOptions> hope this helps.

global class Multipicklist  {
  public list<string> checkboxSelections {get;set;}
  public list<SelectOption> options {get;set;}

  Multipicklist(){
    getPicklistValues(new Account(), 'Type');
  }

  global void getPicklistValues(SObject Account, String Dummy){
    options = new list<SelectOption>();

    // Get the object type of the SObject.
    Schema.sObjectType objType = Account.getSObjectType(); 

    // Describe the SObject using its object type.
    Schema.DescribeSObjectResult objDescribe = objType.getDescribe();       

    // Get a map of fields for the SObject
    map<String, Schema.SObjectField> fieldMap = objDescribe.fields.getMap(); 

    // Get the list of picklist values for this field.
    list<Schema.PicklistEntry> values = fieldMap.get(Dummy).getDescribe().getPickListValues();

    // Add these values to the selectoption list.
    for (Schema.PicklistEntry a : values) { 
        options.add(new SelectOption(a.getLabel(), a.getValue())); 
    }
  } 
}
1
  • Thanks ahtnasah.li. I have edited my code again.Now it looks fine as i am having getter and setter but still it is throwing error.i have kept debug logs but i am not getting my logs also.Still getting the error.Just i want to know what mistake have i done.
    – Jack vardy
    Nov 5, 2015 at 6:22
0

Apex class :

global class Multipicklist {

    global list<SelectOption> picklistValues{get;set;}

    global  Multipicklist(){

  picklistValues = new list<SelectOption>();
        System.debug('value of picklistValues :::'+picklistValues);

  // Get the list of picklist values for this field.
  Schema.DescribeFieldResult fieldResult = Account.Dummy__c.getDescribe();
        System.debug('value of fieldResult :::'+fieldResult);
  list<Schema.PicklistEntry> values = fieldResult.getPickListValues();

        System.debug('value of values :::'+values);
  // Add these values to the selectoption list.
  for (Schema.PicklistEntry a : values)
  { 
     picklistValues.add(new SelectOption(a.getLabel(), a.getValue())); 
      System.debug('value of picklist added :::'+picklistValues);
  }

 }
}

VF Page:

<apex:page controller="Multipicklist" >
    <apex:form>
        <apex:pageblock>
            <apex:pageBlockSection>
    <apex:selectCheckboxes >
    <apex:selectOptions value="{!PicklistValues}"></apex:selectOptions>
</apex:selectCheckboxes>
                </apex:pageBlockSection>
            </apex:pageblock>
        </apex:form>
</apex:page>

You must log in to answer this question.

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