function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
di_zoudi_zou 

How do I get a selectList in my VF page for a custom case controller to work?

I have a VisualForce page that uses a custom controller. This is my controller:

 

global class CompanyCasesQuery {

    //constructors and variable declaration
    
    global List<Case> results {
        get {
            //returns a list of cases
            
            return results;
        } 
        set; 
    }
    
    public List<SelectOption> getItems() {
        List<SelectOption> options = new List<SelectOption>();
        options.add(new SelectOption('00BW0000000PeSVMA0','View All Open Cases'));
        options.add(new SelectOption('00BW0000000PbzWMAS','View All Cases'));
        options.add(new SelectOption('00BW0000000PeSGMA0','View All Closed Cases'));
        options.add(new SelectOption('00B300000005XQtEAM','Recently Viewed Cases'));
        return options;
    }
        
    public String[] getFilterId() {
        return filterid;
    }
        
    public void setFilterId(String[] filterid) {
        this.filterid = filterid;
    }
}

 

This is my VisualForce page:

 

<apex:page controller="CompanyCasesQuery" sidebar="true" showHeader="true">
    <apex:form >
        <apex:pageBlock title="My Cases">
              <apex:outputLabel value="View:"/>
              <apex:selectList value="{!filterId}" size="1">
                <apex:actionSupport event="onchange" action="{!results}" rerender="cases_table"/>
                <apex:selectOptions value="{!items}"/>
              </apex:selectList>
            <apex:pageBlock >
                <apex:pageBlockTable value="{!results}" var="c" rows="50" id="cases_table" >
                    <apex:column >
                        <a target="_parent" href="/{!c.id}">{!c.CaseNumber}</a>
                        <apex:facet name="header">Case Number</apex:facet>
                    </apex:column>
                </apex:pageBlockTable>
            </apex:pageBlock>
        </apex:pageBlock>
    </apex:form>
</apex:page>

The cases show up correctly and the select list shows up correctly. However, when I select an option in my select list, nothing happens. What I would like to have happen is when I select an option in the select list, my cases refresh like the default Salesforce cases page. When I select "View All Cases", all cases are displayed, when I select "View All Closed Cases", only closed cases are displayed. How do I get this select list refresh to work? Thanks.

 

Best Answer chosen by Admin (Salesforce Developers) 
SammyComesHereSammyComesHere
Exact same Code that works for me ... Put it and c for yourself :)

<apex:page controller="CompanyCasesQuery" sidebar="true" showHeader="true"> <apex:form > <apex:pageBlock title="My Cases"> <apex:outputLabel value="View:"/> <apex:selectList value="{!filterId}" size="1"> <apex:actionSupport event="onchange" action="{!processRequests}" rerender="cases_table"/> <apex:selectOptions value="{!items}"/> </apex:selectList> <apex:pageBlock > <apex:pageBlockTable value="{!results}" var="c" rows="50" id="cases_table" > <apex:column headerValue="Case Id"> <a target="_parent" href="/{!c.id}">{!c.CaseNumber}</a> <apex:facet name="header">Case Number</apex:facet> </apex:column> <apex:column headerValue="Account Id "> {!c.AccountId} </apex:column> <apex:column headerValue="Case Number"> {!c.CaseNumber} </apex:column> </apex:pageBlockTable> </apex:pageBlock> </apex:pageBlock> </apex:form> </apex:page>

 

global class CompanyCasesQuery {

    public List<Case> results {get;set;}
    public String filterId {get;set;}
    
    public CompanyCasesQuery ()
    {
    results = new List<Case>();
    
    }

     public PageReference processRequests()
     {
     //write the query for getting the data based on filterId
     results = [select Id,CaseNumber,AccountId from case where Status = :filterId limit 10]; 
     return null;
     }
    
    public List<SelectOption> getItems() {
        List<SelectOption> options = new List<SelectOption>();
        options.add(new SelectOption('','Select'));
        options.add(new SelectOption('Closed','Closed'));
        options.add(new SelectOption('New','New'));
        options.add(new SelectOption('Working','Working'));
        return options;
    }
}

  Please mark as closed when done

All Answers

SammyComesHereSammyComesHere
This should do it i believe. Looks more or less like Cases .. May be you want to use them


global class CompanyCasesQuery {

    public List<Your Object> results {get;set;}
public String filterId {get;set}

CompanyCasesQuery ()
{
results = new List<Your Custom Object>();

}

public PageReference processRequest()
{
write the query for getting the data based on filterId
results = [select Id,Case Number from case where Status = :filterId];
return null;
}
    
    public List<SelectOption> getItems() {
        List<SelectOption> options = new List<SelectOption>();
        options.add(new SelectOption('00BW0000000PeSVMA0','View All Open Cases'));
        options.add(new SelectOption('00BW0000000PbzWMAS','View All Cases'));
        options.add(new SelectOption('00BW0000000PeSGMA0','View All Closed Cases'));
        options.add(new SelectOption('00B300000005XQtEAM','Recently Viewed Cases'));
        return options;
    }
}

 

This is my VisualForce page:

 

<apex:page controller="CompanyCasesQuery" sidebar="true" showHeader="true">
    <apex:form >
        <apex:pageBlock title="My Cases">
         <apex:outputLabel value="View:"/>
          <apex:selectList value="{!filterId}" size="1">
           <apex:actionSupport event="onchange" action="{!processRequests}"  rerender="cases_table"/>
             <apex:selectOptions value="{!items}"/>
           </apex:selectList>
            <apex:pageBlock >
                <apex:pageBlockTable value="{!results}" var="c" rows="50" id="cases_table" >
                    <apex:column >
                        <a target="_parent" href="/{!c.id}">{!c.CaseNumber}</a>
                        <apex:facet name="header">Case Number</apex:facet>
                    </apex:column>
                </apex:pageBlockTable>
            </apex:pageBlock>
        </apex:pageBlock>
    </apex:form>
</apex:page>
di_zoudi_zou

I just tried this and and I get an empty list of cases.

SammyComesHereSammyComesHere
SammyComesHereSammyComesHere
Exact same Code that works for me ... Put it and c for yourself :)

<apex:page controller="CompanyCasesQuery" sidebar="true" showHeader="true"> <apex:form > <apex:pageBlock title="My Cases"> <apex:outputLabel value="View:"/> <apex:selectList value="{!filterId}" size="1"> <apex:actionSupport event="onchange" action="{!processRequests}" rerender="cases_table"/> <apex:selectOptions value="{!items}"/> </apex:selectList> <apex:pageBlock > <apex:pageBlockTable value="{!results}" var="c" rows="50" id="cases_table" > <apex:column headerValue="Case Id"> <a target="_parent" href="/{!c.id}">{!c.CaseNumber}</a> <apex:facet name="header">Case Number</apex:facet> </apex:column> <apex:column headerValue="Account Id "> {!c.AccountId} </apex:column> <apex:column headerValue="Case Number"> {!c.CaseNumber} </apex:column> </apex:pageBlockTable> </apex:pageBlock> </apex:pageBlock> </apex:form> </apex:page>

 

global class CompanyCasesQuery {

    public List<Case> results {get;set;}
    public String filterId {get;set;}
    
    public CompanyCasesQuery ()
    {
    results = new List<Case>();
    
    }

     public PageReference processRequests()
     {
     //write the query for getting the data based on filterId
     results = [select Id,CaseNumber,AccountId from case where Status = :filterId limit 10]; 
     return null;
     }
    
    public List<SelectOption> getItems() {
        List<SelectOption> options = new List<SelectOption>();
        options.add(new SelectOption('','Select'));
        options.add(new SelectOption('Closed','Closed'));
        options.add(new SelectOption('New','New'));
        options.add(new SelectOption('Working','Working'));
        return options;
    }
}

  Please mark as closed when done

This was selected as the best answer
di_zoudi_zou

It works for me now. It was the select options that I had wrong. Thanks a lot!