You need to sign in to do that
Don't have an account?
T L TEJASWINI
How to display dynamically custom object record names in a visual force page in picklist
My code is at present hard coded
vf page
======
<apex:page controller="EmployeeDataClass">
<apex:form >
<apex:pageBlock title="Department:" >
<apex:outputText value="{!selectedEmp}" label="you have selected:"/>
<apex:pageBlockSection title="Custom Picklist Using selectList and selectOptions departments" collapsible="false">
<apex:selectList value="{!selectedEmp}" multiselect="false" size="1">
<apex:selectOptions value="{!countriesOptions}"/>
</apex:selectList>
</apex:pageBlockSection>
<apex:pageBlock title="Employee Data">
<apex:pageBlockTable value="{!lstEmp}" var="e">
<apex:column headerValue="Employee Name" >
<apex:outputtext value="{!e.Name}"></apex:outputtext>
</apex:column>
<apex:column headerValue="Employee City" >
<apex:outputtext value="{!e.Email__c}"></apex:outputtext>
</apex:column>
<apex:column headerValue="Employee Contact" >
<apex:outputtext value="{!e.Phone__c}"></apex:outputtext>
</apex:column>
<apex:column headerValue="Employee department" >
<apex:outputtext value="{!e.Dept__c}"></apex:outputtext>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:pageBlock>
</apex:form>
</apex:page>
controller
========
public class EmployeeDataClass{
/*
constructor is a method which executes automatically when the class is loaded.
*/
public List<Employee__c> lstEmp{get;set;} // Property Declaration.
public String selectedEmp{get;set;}
public EmployeeDataClass(){
lstEmp = new List<Employee__c>(); // Initialization.
lstEmp = [select id,name,email__c,phone__c,dept__c from Employee__c limit 50000];
}
public List<SelectOption> getCountriesOptions() {
List<SelectOption> countryOptions = new List<SelectOption>();
countryOptions.add(new SelectOption('','-None-'));
countryOptions.add(new SelectOption('Learning','Learning'));
countryOptions.add(new SelectOption('HR','HR'));
countryOptions.add(new SelectOption('Accounts and Finance','Accounts and Finance'));
countryOptions.add(new SelectOption('Infrastructures','Infrastructures'));
countryOptions.add(new SelectOption('Research and development','Research and development'));
countryOptions.add(new SelectOption('Product development','Product development'));
countryOptions.add(new SelectOption('IT services','IT services'));
return countryOptions;
}
public PageReference save(){
return null;
}
}
===================
Now I want code in controller to be dynamic.Please suggest any ideas.
vf page
======
<apex:page controller="EmployeeDataClass">
<apex:form >
<apex:pageBlock title="Department:" >
<apex:outputText value="{!selectedEmp}" label="you have selected:"/>
<apex:pageBlockSection title="Custom Picklist Using selectList and selectOptions departments" collapsible="false">
<apex:selectList value="{!selectedEmp}" multiselect="false" size="1">
<apex:selectOptions value="{!countriesOptions}"/>
</apex:selectList>
</apex:pageBlockSection>
<apex:pageBlock title="Employee Data">
<apex:pageBlockTable value="{!lstEmp}" var="e">
<apex:column headerValue="Employee Name" >
<apex:outputtext value="{!e.Name}"></apex:outputtext>
</apex:column>
<apex:column headerValue="Employee City" >
<apex:outputtext value="{!e.Email__c}"></apex:outputtext>
</apex:column>
<apex:column headerValue="Employee Contact" >
<apex:outputtext value="{!e.Phone__c}"></apex:outputtext>
</apex:column>
<apex:column headerValue="Employee department" >
<apex:outputtext value="{!e.Dept__c}"></apex:outputtext>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:pageBlock>
</apex:form>
</apex:page>
controller
========
public class EmployeeDataClass{
/*
constructor is a method which executes automatically when the class is loaded.
*/
public List<Employee__c> lstEmp{get;set;} // Property Declaration.
public String selectedEmp{get;set;}
public EmployeeDataClass(){
lstEmp = new List<Employee__c>(); // Initialization.
lstEmp = [select id,name,email__c,phone__c,dept__c from Employee__c limit 50000];
}
public List<SelectOption> getCountriesOptions() {
List<SelectOption> countryOptions = new List<SelectOption>();
countryOptions.add(new SelectOption('','-None-'));
countryOptions.add(new SelectOption('Learning','Learning'));
countryOptions.add(new SelectOption('HR','HR'));
countryOptions.add(new SelectOption('Accounts and Finance','Accounts and Finance'));
countryOptions.add(new SelectOption('Infrastructures','Infrastructures'));
countryOptions.add(new SelectOption('Research and development','Research and development'));
countryOptions.add(new SelectOption('Product development','Product development'));
countryOptions.add(new SelectOption('IT services','IT services'));
return countryOptions;
}
public PageReference save(){
return null;
}
}
===================
Now I want code in controller to be dynamic.Please suggest any ideas.
Greetings to you!
Below is the sample code. Kindly modify the code as per your requirement.
Visualforce:
Controller:
I hope it helps you.
Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.
Thanks and Regards,
Khan Anas