0

In my vf page the date is presented based on only one value of the status picklist for the opportunists object.

Now i need to extend my search criteria in such as way that rather than selecting only one stagename, i need to pass multi select picklist value to query such that it can select any multi value from front end to soql query

I tried passing the stagename fields is only picklist and even i try to pass a multi select value to query i

Vf Page

<apex:page controller="Pagination_min">
  <apex:form >
      <apex:pageBlock id="pb">
                <apex:pageBlockSection >
      <apex:selectList value="{!shiftType}" multiselect="false" size="1" 
                       label="Shift Types" title="Users" onchange="show()" >
            <apex:selectOption itemValue="Closed Won" itemLabel="Closed Won"/>                
            <apex:selectOption itemValue="Closed Lost" itemLabel="Closed lost"/>
            <apex:selectOption itemValue="Needs Analysis" itemLabel="need"/>
            <apex:selectOption itemValue="Qualification" itemLabel="Qualification"/>
      </apex:selectList>

      </apex:pageBlockSection>
          <apex:pageBlockTable value="{!Accounts}" var="a">
              <apex:column value="{!a.Name}"/>
              <apex:column value="{!a.closeDate}"/>
              <apex:column value="{!a.stageName}"/>                   
          </apex:pageBlockTable>
          <apex:panelGrid columns="7">
              <apex:commandButton status="fetchStatus" reRender="pb" value="|<" action="{!setCon.first}" disabled="{!!setCon.hasPrevious}" title="First Page"/>
              <apex:commandButton status="fetchStatus" reRender="pb" value="<" action="{!setCon.previous}" disabled="{!!setCon.hasPrevious}" title="Previous Page"/>
              <apex:commandButton status="fetchStatus" reRender="pb" value=">" action="{!setCon.next}" disabled="{!!setCon.hasNext}" title="Next Page"/>
              <apex:commandButton status="fetchStatus" reRender="pb" value=">|" action="{!setCon.last}" disabled="{!!setCon.hasNext}" title="Last Page"/>
              <apex:outputText >{!(setCon.pageNumber * size)+1-size}-{!IF((setCon.pageNumber * size)>noOfRecords, noOfRecords,(setCon.pageNumber * size))} of {!noOfRecords}</apex:outputText>
              <apex:commandButton status="fetchStatus" reRender="pb" value="Refresh" action="{!refresh}" title="Refresh Page"/>
              <apex:actionFunction name="show" action="{!refresh}" reRender="pb" />
              <apex:selectList value="{!size}" multiselect="false" size="1" onchange="show()">
                    <apex:selectOptions value="{!items}"/>
                 </apex:selectList>     
              <apex:outputPanel style="color:#4AA02C;font-weight:bold">
                  <apex:actionStatus id="fetchStatus" startText="Fetching..." stopText=""/>
              </apex:outputPanel>
          </apex:panelGrid>
          <apex:actionFunction name="show" action="{!refresh}" reRender="pb" />
      </apex:pageBlock>
  </apex:form>

public with sharing class Pagination_min {

  public String shiftType { get; set; }    
  Public Integer noOfRecords{get; set;}
  Public Integer size{get;set;}
  public boolean test = false;
  public       Pagination_min() {
     shiftType='Closed Won';
     refresh();
  }
  public ApexPages.StandardSetController setCon {
   get{
     if(setCon == null){
       if(test == false){
         size = 10;
       }
       string queryString = 'Select Name, closeDate, stageName 
        from Opportunity where stageName =:shiftType order by Name';
       setCon = new ApexPages.StandardSetController(Database.getQueryLocator(queryString));
       setCon.setPageSize(size);
       noOfRecords = setCon.getResultSize();
       test = true;
     }
     return setCon;
    }set;
  }

 Public List<Opportunity> getAccounts(){
   List<Opportunity> accList = new List<Opportunity>();
   for(Opportunity a : (List<Opportunity>)setCon.getRecords())
     accList.add(a);
   return accList;
 }

public pageReference refresh() {
   setCon = null;
   getAccounts();
   setCon.setPageNumber(1);
   return null;
}
public List<SelectOption> getItems() {
  List<SelectOption> options = new List<SelectOption>();
  options.add(new SelectOption('10','10'));
  options.add(new SelectOption('20','20'));
  options.add(new SelectOption('30','30'));
  return options;
}
  }
2
  • 1
    (1) please strip out portions of the apex code and vf page not relevant to the question (like the pagination); (2) define what is not working and the results you are getting
    – cropredy
    Jan 22, 2015 at 17:32
  • I can change the vf code as required. but for apex code, the query is fetched using standard controller , and cant remove it. The code is a simple pickilist value search from Vf to apex and the returned query is paginated using standard set controller. Here only we have only picklist value to be search at a time like only "Closed Won" the all the records will be of Closed Won status only, and "Closed Lost" will give you records based on Closed lost status only. i am trying to select both from vf like a multipicklist which should bring me both the status records in one go.
    – chops
    Jan 23, 2015 at 4:36

2 Answers 2

1

A few points:

The VF page selectList:

   <apex:selectList value="{!shiftType}" multiselect="false" size="1" 
                   label="Shift Types" title="Users" onchange="show()" >
        <apex:selectOption itemValue="Closed Won" itemLabel="Closed Won"/>                
        <apex:selectOption itemValue="Closed Lost" itemLabel="Closed lost"/>
        <apex:selectOption itemValue="Needs Analysis" itemLabel="need"/>
        <apex:selectOption itemValue="Qualification" itemLabel="Qualification"/>
  </apex:selectList>

is defined as multiSelect="false". If you want multiple values to be selected by the user, then this attribute needs to be true

The value transmitted to the VF controller property as a setter shiftType will be a string delimited by semi-colons of the selected item(s)

The SOQL query:

string queryString = 'Select Name, closeDate, stageName 
    from Opportunity where stageName =:shiftType order by Name';

will not work as is for multi-select values. As Stagename is not a MultiSelect field, you can't use the includes SOQL operator. Instead, you will use the IN operator and convert the user-selected MSP to a list as in:

string[] selectedShiftTypeList = this.shiftType.split(';');
string queryString = 'Select Name, closeDate, stageName 
    from Opportunity where stageName IN :selectedShiftTypeList order by Name';
0

yes, it is because in your

string queryString = 'Select Name, closeDate, stageName 
        from Opportunity where stageName =:shiftType order by Name';

you are binding stage name with string datatype although you want multiselect picklist possible values.

so, instead of String shiftType you use Set shiftType and make slight changes in your query

string queryString = 'Select Name, closeDate, stageName 
    from Opportunity where stageName IN :shiftType order by Name';

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .