Activity Forums Salesforce® Discussions How can I create custom picklist on a Salesforce Visualforce Page? Reply To: How can I create custom picklist on a Salesforce Visualforce Page?

  • Adarsh

    Member
    March 22, 2018 at 12:51 pm

    Hi Ankit,

    you may go through with this sample of code,

    <apex:page controller="TestController ">
    <apex:form >
    <apex:selectList size="1" value="{!selectedname}">
    <apex:selectOptions value="{!selectedaccnamefields}"/>
    </apex:selectList>
    </apex:form>
    </apex:page>

    public class TestController {
    Public string selectedname{get;set;}
    Public List<Selectoption> getselectedaccnamefields(){
    List<Selectoption> lstnamesel = new List<selectoption>();
    lstnamesel.add(new selectOption('', '- None -'));
    for(Account acc :[SELECT id,name,phone,type,industry FROM Account]){
    lstnamesel.add(new selectoption(acc.id,acc.name));
    }
    return lstnamesel;
    }
    }

    Hope it helps 🙂