0

Page

<apex:page standardController="Account" extensions="PickListClass">
    <apex:form >
        <apex:pageBlock >
            <apex:pageBlockSection >            
            <apex:commandButton value="Save" action="{!Save}"/><br/>
            <apex:inputText value="{!Account.Name}" />
            <apex:selectList value="{!Rating}" multiselect="false" size="1">
                <apex:selectOptions value="{!RatingOptions}"/>
                </apex:selectList>
            </apex:pageBlockSection>

        </apex:pageBlock>
    </apex:form>
</apex:page>

Controller

public class PickListClass{
     public ApexPages.StandardController stdCntrlr {get; set;}
    public void PickListClass(ApexPages.StandardController controller)
    {
        stdCntrlr = controller;
    }

    public String Rating{get; set;}
    public List<String> selectedCategories { get; set; }
    public List<SelectOption> getRatingOptions() {
        List<SelectOption> RatingOptions = new List<SelectOption>();
        RatingOptions.add(new SelectOption('','-None-'));
        RatingOptions.add(new SelectOption('Hot','Hot'));
        RatingOptions.add(new SelectOption('Warm','Warm'));
        RatingOptions.add(new SelectOption('Cold','Cold'));

        return RatingOptions;
    }



}
  • Have you looked at the documentation on how to create a custom controller to define the constructor? You may also want to think about your naming since there may already be a picklist class for standard visualforce. I know there's a dynamicpicklist class found in the apex docs.. – crmprogdev Oct 3 '17 at 13:27
3

Constructors do not have a return type.

Incorrect

public class PickListClass{
    public void PickListClass(ApexPages.StandardController controller)
    //     ^^^^
    {
        // not a constructor
    }
}

Correct

public class PickListClass{
    public PickListClass(ApexPages.StandardController controller)
    {
        // now it is a constructor
    }
}
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.