Activity Forums Salesforce® Discussions How to use picklist field in Visualforce page in Salesforce ?

  • Shweta

    Member
    February 18, 2020 at 12:24 pm

    To show a list of values in Visualforce first create the Apex class :

    public class TestClass {
        public String selectedaccId {set;get;}
        List<selectOption> options=new List<selectoption>();
        public TestClass(){
            selectedaccId ='';
        }  
        public List<SelectOption> getListOfAccount(){
            options.add(new selectOption('','--Select--'));
            for(Account acc:[select id,name from account ]){
                options.add(new selectOption(acc.id,acc.name));
            }
            return options; 
        }
    }

    And then display it on Visualforce page :

    <apex:page controller="TestClass">
        <apex:form >
            <apex:pageBlock title="Account Name">
                <apex:pageMessages />
                <apex:pageBlockSection >
                    <apex:OutputPanel >
                        <apex:selectList label="Account Name" value="{!selectedaccId}" size="1" multiselect="false" required="true"  >
                            <apex:selectOptions value="{!ListOfAccount}"  />
                        </apex:selectList>
                    </apex:OutputPanel> 
                </apex:pageBlockSection>
            </apex:pageBlock>
        </apex:form>
    </apex:page>

     

     

  • Pooja

    Member
    February 23, 2020 at 4:16 pm

    To show a list of values in Visualforce first create the Apex class And then display it on Visualforce page .

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos