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
PeacePeace 

Display a VF page after clickin on command button, depending on selected value from list box

Hi,

 

i am new to salesforce. i hv a simple doubt:

 

 

 public PageReference GotoCSV() {
 
  if (selectedValue == 'FlatFile')
            {        
  PageReference newpage = new PageReference('/apex/UploadAccounts1');

           newpage.setRedirect(true);
           return newpage; 
}
    }

 

i want to display 'UploadAccounts1' page when user selects 'FlatFile' from the dropdown list and clicks the command button.  however m getting following error in the controller   "Non-void method might not return a value or might have statement after a return statement"

 

 

this is my VF page:

<apex:form >
        &nbsp;&nbsp; <font color='grey'> Connection type &nbsp;&nbsp;  </font><apex:selectList id="chooseColor" value="{!string}" size="1">
         <apex:selectOption itemValue="Any connection type" itemLabel="- - Any connection type - -"/>
         <apex:selectOption itemValue="FlatFile" itemLabel="Flat File"/>
                 <apex:selectOption itemValue="SQLServer2008" itemLabel="SQL Server 2008"/>
            <apex:selectOption itemValue="MsAccess" itemLabel="MS Access"/>
        </apex:selectList>

<apex:commandButton action="{!GotoCSV}" value="Create Connection" id="theBtn1" style="width:100px; height: 25px;"/>     
</apex:form>

 

Can anyone please provide a solution

Best Answer chosen by Admin (Salesforce Developers) 
Bhawani SharmaBhawani Sharma
Change
<apex:selectList id="chooseColor" value="{!string}" size="1">
to
<apex:selectList id="chooseColor" value="{!selectedValue}" size="1">

All Answers

Bhawani SharmaBhawani Sharma
Change to this

public PageReference GotoCSV() {

if (selectedValue == 'FlatFile')
{
PageReference newpage = new PageReference('/apex/UploadAccounts1');

newpage.setRedirect(true);
return newpage;
}
return null;
}
PeacePeace

Hi,

 

I tried adding    return null;  but then it remains on the same page no matter whatever I select from the drop down.

 

Please provide another solution

Bhawani SharmaBhawani Sharma
Make sure your are slectimg selectedValue as "FlatFile".Only in that case, page will be navigated to UploadAccounts1 screen
Bhawani SharmaBhawani Sharma
Change
<apex:selectList id="chooseColor" value="{!string}" size="1">
to
<apex:selectList id="chooseColor" value="{!selectedValue}" size="1">
This was selected as the best answer
PeacePeace

ya i already found that mistake and it worked fine..

 

anyway Thanks

Bhawani SharmaBhawani Sharma
Can you mark this as resolved, So it will help others who are facing same issue.