I have a commandbutton on a VF page that calls a method in the controller that should redirect to a new pagereference. When I select a value from a Selectcheckboxes control, the page will not redirect and it appears that the method that should be called from the commandbutton is never invoked. I tried debugging, but none of my debugs show in the log. I also tried disabling development mode. No luck.

public PageReference toResultsPage()
    //do stuff
    PageReference page = new PageReference(
    return page.setredirect(false);  

And the VF part:

<div class="col-md-12">  
    <div class="form-group text-center">  
        <apex:commandButton value="Enhanced Search" action="{!toResultsPage}" id="submit-search" styleClass="btn btn-primary gradient"/>      
  • Can you post the code which does the redirection please ?
    – SF_user
    Commented Dec 23, 2015 at 15:09
  • Just added the method in the page controller. This works if fileFilters is empty, but fails if I select any of the checkboxes associated with filetypefilters
    – Stephen
    Commented Dec 23, 2015 at 16:50
  • Please also post the markup for your commandButton.
    – Adrian Larson
    Commented Dec 23, 2015 at 17:53
  • do you see any required field on your vf page ?
    – Himanshu
    Commented Dec 23, 2015 at 19:13
  • There are no required fields on my page, but I do think I'm having an issue with validation. Any thoughts?
    – Stephen
    Commented Dec 23, 2015 at 19:46

2 Answers 2


The problem was that I didn't initialize the list returned by the checkboxes control. This line: filetypefilter=new list(); in the page constructor was not present in my original code and was causing the method called by the commandButton to fail, without an error. Also, if no values were selected from the list the method would fire, sending an email with no values. I could then make selections from the list and they would show in the email.

<apex:page controller="debugpage">  
<apex:form >
    <div class="col-md-4">           
        <h4>Refine by Document Type</h4>
        <apex:outputPanel id="files">
            <apex:selectCheckboxes value="{!fileTypeFilter}"  layout="pageDirection">
                <apex:selectOptions value="{!filelist}"/>
    <apex:commandButton Action="{!MethodName}" value="Emailresult"/>  

public with sharing class debugpage {

public list<selectoption> fileList{get;set;}//list to populate document type boolean list
public list<string> fileTypeFilter{get;set;}//list returned from filetype filter

public debugpage(){

    filetypefilter=new list<string>();
    filelist=new list<selectoption>();
    list<AggregateResult> extensionList=new list<AggregateResult>();//initialize list for file_type_families__c
    extensionlist=[select  extension_family__c from file_type_family__c group by extension_family__c]; //query for file type families       
    for(aggregateResult ar:extensionlist){//for each record returned in query for file type families add to filelist as a selectoption
        fileList.add(new SelectOption((string)ar.get('Extension_Family__c'),(string)ar.get('Extension_Family__c') ));
public PageReference MethodName() {

List<Messaging.SingleEmailMessage> mails =  new List<Messaging.SingleEmailMessage>(); 
String[] toAddresses = new String[] {'[email protected]'};

Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();  
mail.setReplyTo('[email protected]');
mail.setSenderDisplayName('System Automated Message');
mail.setSubject('What got Selected');

String body = 'settings ';
For (String i : FileTypeFilter){
    Body+= 'Line '+i;

    return null;



If you want the PageReference to cause a redirect, don't call setRedirect(false). The default value is true.

Aside from this correction, you should construct your PageReference in such a way that it will work across all environments.

PageReference redirect = Page.SearchResults;
redirect.getParameters().put(searchString, someValue);
// etc.
return redirect;
  • the page will go to the requested page whether redirect is true or false. It's set to false because I want to maintain the state of the page. The page that I'm redirecting to will use the same controller.
    – Stephen
    Commented Dec 23, 2015 at 18:48

You must log in to answer this question.

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