You need to sign in to do that
Don't have an account?
rubel rana 6
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 :
Thanks
Kind regards,
Rubel
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.
My goal is to use this value in a query. like
select * from variable_nameSo 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:selectList><p/> <apex:pageBlock title="Results in Range"> <apex:pageBlockTable value="{!cts}" var="ct"> <apex:column value="{!ct.Name}"/> <apex:column value="{!ct.AccountNumber}"/> </apex:pageBlockTable> </apex:pageBlock> </apex:form> <!-- 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> </apex:outputPanel> </apex:facet> </apex:actionstatus> </apex:outputPanel> <!-- dropdown list ends --> </apex:page>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; System.debug(query); cts = Database.query(query); } public void clearResults() { cts.clear(); } }
Thanks
Kind regards,
Rubel