+ Start a Discussion
rubel rana 6rubel rana 6 

Getting value of dropdown list into controller

Hello everyone !
I am  newbie in Salesforce. 
I am facing problems to get value of dropdown list into controller. 
User-added imageMy goal is to use this value in a query. like

select * from variable_name
So that, I can select any object from dropdown list and I can see all the results of the object.
Below, I am adding my code sample that I am trying. But, it's not working. Can anyone help me to figure out what to do next or modify in this code?

Page :
<apex:page docType="html-5.0" controller="ContactsByDateController" >
    <apex:form >
        <apex:commandButton value="Search results" action="{!datepick1}"/>
        <apex:commandButton value="Clear results" action="{!clearResults}"/>
        <apex:selectList value="{!countries}" multiselect="true" size="3">
            <apex:selectOptions value="{!items}"/>
        <apex:pageBlock title="Results in Range">
            <apex:pageBlockTable value="{!cts}" var="ct">
                <apex:column value="{!ct.Name}"/>
                <apex:column value="{!ct.AccountNumber}"/>
    <!-- dropdown list starts -->
    <apex:outputPanel id="out">
        <apex:actionstatus id="status" startText="testing...">
            <apex:facet name="stop">
                <apex:outputPanel >
                    <p>You have selected:</p>
                    <apex:dataList value="{!countries}" var="c">{!c}</apex:dataList>
    <!-- dropdown list ends -->
Controller : 
public class ContactsByDateControllerr {
public List<Account> cts {get;set;}
String[] countries = new String[]{};    
public ContactsByDateControllerr() {
    /* dropdown list start 
     * */
       public List<SelectOption> getItems() {
        List<SelectOption> options = new List<SelectOption>();
        options.add(new SelectOption('Account','Account'));
        options.add(new SelectOption('Contacts','Contacts'));
        options.add(new SelectOption('Jobs__c','JObs'));
        options.add(new SelectOption('My_leads__c','My Leads'));
		options.add(new SelectOption('My_Customers__c','My Customers'));
        return options;
     public String[] getCountries() {
        return countries;

    public void setCountries(String[] countries) {
        this.countries = countries;
    /* dropdown list ends 
     * */

    /* variable assigning for selected list from dropdown*/
public void datepick1() {
String query = 'SELECT * FROM'+ countries;

cts = Database.query(query);
public void clearResults() {

Kind regards,