You need to sign in to do that
Don't have an account?
sai harish
Need help passing List<selectoption> in to my query.
This might be simple but I am unable to figure out what I am missing. I need to get Project Managers from the VF page and pass them in to my Query. Here is my Apex class and my VF page.
Class :
public class ProjectsFilterByDates{
public ProjectsFilterByDates(ApexPages.StandardController stdController) {
}
Date StartDate;
Date EndDate;
public String DateStringProperty{get;set;}
List<AcctSeed__Project__c> results;
String[] ProjectManagers = new String[]{};
public Date getstartDate(){
return StartDate;
}
public Date getEndDate(){
return EndDate;
}
Public List<AcctSeed__Project__c> getresults(){
return results;
}
public void setStartDate(Date input){
StartDate = input;
}
public void setEndDate(Date input1){
EndDate = input1;
}
public List<SelectOption> getListOfUser(){
List<User> Users = [select Name from user Where Project_Manager__c = true Order By Name ASC] ;
List<SelectOption> options = new List<SelectOption>();
for(User u : Users)
{
options.add(new SelectOption(u.Id , u.Name));
}
return options;
}
public String[] getProjectManagers (){
return ProjectManagers;
}
public void setProjectManagers (string[] ProjectManagers){
this.ProjectManagers = ProjectManagers;
}
public PageReference Search(){
results = [SELECT Name,UserID__c,AcctSeed__Account__r.Name,Date_Created__c,Construction_Manager__r.Name,AcctSeedERP__Manufactured_Product__r.Name,Project_Manager__c FROM AcctSeed__Project__c WHERE Date_Created__c >= :StartDate AND Date_Created__c <= :EndDate AND Project_Manager__c =:ProjectManagers order by Date_Created__c desc ];
return null;
}
}
VF Page:
<apex:page Standardcontroller="AcctSeed__Project__c" extensions="ProjectsFilterByDates" showHeader="false" sidebar="false" docType="html-5.0" language="en_Us" >
<apex:form >
<apex:pageBlock >
Start Date: <apex:input type="date" value="{!StartDate}"/>
End Date: <apex:input type="date" value="{!EndDate}"/>
<apex:selectList value="{!ProjectManagers}" size="5" multiselect="true">
<apex:selectOptions value="{!ListOfUser}"/>
</apex:selectList><p/>
<apex:commandButton value="Search For Projects" action="{!search}"/>
<apex:pageBlockTable value="{!results}" var="p">
<apex:column value="{!p.Name}"/>
<apex:column value="{!p.AcctSeed__Account__r.Name}"/>
<apex:column value="{!p.Project_Manager__c}"/>
<apex:column value="{!p.Date_Created__c}"/>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
Class :
public class ProjectsFilterByDates{
public ProjectsFilterByDates(ApexPages.StandardController stdController) {
}
Date StartDate;
Date EndDate;
public String DateStringProperty{get;set;}
List<AcctSeed__Project__c> results;
String[] ProjectManagers = new String[]{};
public Date getstartDate(){
return StartDate;
}
public Date getEndDate(){
return EndDate;
}
Public List<AcctSeed__Project__c> getresults(){
return results;
}
public void setStartDate(Date input){
StartDate = input;
}
public void setEndDate(Date input1){
EndDate = input1;
}
public List<SelectOption> getListOfUser(){
List<User> Users = [select Name from user Where Project_Manager__c = true Order By Name ASC] ;
List<SelectOption> options = new List<SelectOption>();
for(User u : Users)
{
options.add(new SelectOption(u.Id , u.Name));
}
return options;
}
public String[] getProjectManagers (){
return ProjectManagers;
}
public void setProjectManagers (string[] ProjectManagers){
this.ProjectManagers = ProjectManagers;
}
public PageReference Search(){
results = [SELECT Name,UserID__c,AcctSeed__Account__r.Name,Date_Created__c,Construction_Manager__r.Name,AcctSeedERP__Manufactured_Product__r.Name,Project_Manager__c FROM AcctSeed__Project__c WHERE Date_Created__c >= :StartDate AND Date_Created__c <= :EndDate AND Project_Manager__c =:ProjectManagers order by Date_Created__c desc ];
return null;
}
}
VF Page:
<apex:page Standardcontroller="AcctSeed__Project__c" extensions="ProjectsFilterByDates" showHeader="false" sidebar="false" docType="html-5.0" language="en_Us" >
<apex:form >
<apex:pageBlock >
Start Date: <apex:input type="date" value="{!StartDate}"/>
End Date: <apex:input type="date" value="{!EndDate}"/>
<apex:selectList value="{!ProjectManagers}" size="5" multiselect="true">
<apex:selectOptions value="{!ListOfUser}"/>
</apex:selectList><p/>
<apex:commandButton value="Search For Projects" action="{!search}"/>
<apex:pageBlockTable value="{!results}" var="p">
<apex:column value="{!p.Name}"/>
<apex:column value="{!p.AcctSeed__Account__r.Name}"/>
<apex:column value="{!p.Project_Manager__c}"/>
<apex:column value="{!p.Date_Created__c}"/>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
All Answers
Thanks in Advance.
Sai Harish.
Thank you for the help.
Here is my final code which is working.
public class projectManagers{
public String DateStringProperty {get;set;}
public List<AcctSeed__Project__c> results {get;set;}
public Date StartDate {get;set;}
public Date EndDate {get;set;}
String[] ProjectManagers = new String[]{};
public List<SelectOption> getListOfUser(){
List<SelectOption> options = new List<SelectOption>();
for(User u : [Select Id, Name From User Where Project_Manager__c = true Order By Name])
{
options.add(new SelectOption(u.Name,u.Name));
}
return options;
}
public String[] getProjectManagers (){
return ProjectManagers;
}
public void setProjectManagers (string[] ProjectManagers){
this.ProjectManagers = ProjectManagers;
}
public PageReference Search(){
results = [SELECT Id,Name,Project_Manager__c,AcctSeed__Status__c from AcctSeed__Project__c Where AcctSeed__Status__c =:Status AND Project_Manager__c=:ProjectManagers LIMIT 1000];
return null;
}
}
I had to do the part which is in bold other wise Project Managers were not passing in my query.
Thank you so much for the help Santosh.