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
ankitha varraankitha varra 

the selectlist value is not passing from vf page to controller

VF page

<apex:page standardController="Accounts__c" extensions="YesBankAccount" >
<apex:form >
  <apex:selectList size="1" value="{!selResult}" >
<apex:selectOptions value="{!selOptions}" />
</apex:selectlist>

<apex:commandButton value="Go!" action="{!movingtoanotherpage}" />
</apex:form>
</apex:page>

Controller

  Public pagereference movingtoanotherpage(){
     
    if(Selresult == 'Create Account'){
    PageReference pageRef = new PageReference('/apex/YesBankAccountPage');
         Pageref.setredirect(true);
            return pageRef;
   }
    else if(selresult=='show contacts')
    return null; 
    return null;
  }
Whenever we select the value create contact it should navigate to another page,
whenever we select the the value show contacts it should rendered the page block,
but i thought that value is not passing from visual force page to controller
 
Best Answer chosen by ankitha varra
mritzimritzi
The format of selectOption is
new SelectOption(value,Label);

Label is visible to the user, Value is passed to Apex or stored in Apex.

In your Apex code:
Public pagereference movingtoanotherpage(){
    if(selresult!='Show Accounts' && Selresult!='Delete Accounts' && Selresult!='-None-'){
      pagereference p= new pagereference('/apex/YesBankAccountPage');
      p.setredirect(true);
      return p;
 }
   else if(selresult!='Create Account'&& Selresult!='Delete Accounts'&& Selresult!='-None-' ){
       showsection= true;
       return null;
 }
 else if(selresult!='Create Accounts'&& Selresult!='Show Accounts'&& Selresult!='-None-' ){
       return null;
 } else if(selresult!='Create Accounts'&& Selresult!='Delete Accounts'&& Selresult!='Show Accounts' ){
       return null;
 } else
 
 return null;
  }
Replace all these labels with values like: creAcc, none, srchAcc etc

The code will definitely work.


Mark it as BEST ANSWER, if it solves your problem

All Answers

mritzimritzi
Please share complete code, else atleast the part where you are populating the selectList options.
ankitha varraankitha varra
This is the controller

public class YesBankAccount 
{
    public Accounts__c Acc = new Accounts__c();
    
    public List<Accounts__c> accList {get;set;}
    
    public List<selectoption> options{set;get;}
    public List<selectoption> selOptions{set;get;} 
   
    
    public string Result{set;get;}
    public string SelResult{set;get;}
    Public boolean Showsection {get;set;}
    Public Boolean Records {get;set;}
    public YesBankAccount(Apexpages.StandardController Controller)
    {
        acc = (Accounts__c)controller.getrecord();
              
        options = new list<selectoption>();
        selectoption op1 = new selectoption('none','-None-');
        selectoption op2 = new selectoption('All','All Accounts');
        selectoption op3 = new selectoption('Today','Todays Accounts');
        selectoption op4 = new selectoption('Week','This Weeks Accounts');
        selectoption op5 = new selectoption('Month','This Months Accounts');
        
        options.add(op1);
        options.add(op2);
        options.add(op3);
        options.add(op4);
        options.add(op5);
        
        selOptions = new list<selectoption>();
        selectoption sop1 = new selectoption('none','-None-');
        selectoption sop2 = new selectoption('creAcc','Create Account');
        selectoption sop3 = new selectoption('srchAcc','Search Accounts');
        selectoption sop4 = new selectoption('delAcc','Delete Accounts');
        
        selOptions.add(sop1);
        selOptions.add(sop2);
        selOptions.add(sop3);
        selOptions.add(sop4);
     }
    
    public  pagereference newAccForm()
    {        
       pagereference p= new pagereference('/apex/YesBankAccountPage');
       return p;
    }
   
   
   Public pagereference movingtoanotherpage(){
    if(selresult!='Show Accounts' && Selresult!='Delete Accounts' && Selresult!='-None-'){
      pagereference p= new pagereference('/apex/YesBankAccountPage');
      p.setredirect(true);
      return p;
 }
   else if(selresult!='Create Account'&& Selresult!='Delete Accounts'&& Selresult!='-None-' ){
       showsection= true;
       return null;
 }
 else if(selresult!='Create Accounts'&& Selresult!='Show Accounts'&& Selresult!='-None-' ){
       return null;
 } else if(selresult!='Create Accounts'&& Selresult!='Delete Accounts'&& Selresult!='Show Accounts' ){
       return null;
 } else
 
 return null;
  }
  
   Public Pagereference displayingrecords(){
    
    acclist=[Select Name,Name__c,Type_Of_Account__c,Priority__c,Mobile_Number__c,City_Current__c from Accounts__c]; 
   
    return null;
  
    }  
   
}

Vf page

<apex:selectList size="1" value="{!selResult}" >
<apex:selectOptions value="{! selOptions}" />
</apex:selectlist>
<apex:commandButton value="Go!" action="{!movingtoanotherpage}" />

Whats wrong with this code and only if condition is working and else if conditions is not working
mritzimritzi
The format of selectOption is
new SelectOption(value,Label);

Label is visible to the user, Value is passed to Apex or stored in Apex.

In your Apex code:
Public pagereference movingtoanotherpage(){
    if(selresult!='Show Accounts' && Selresult!='Delete Accounts' && Selresult!='-None-'){
      pagereference p= new pagereference('/apex/YesBankAccountPage');
      p.setredirect(true);
      return p;
 }
   else if(selresult!='Create Account'&& Selresult!='Delete Accounts'&& Selresult!='-None-' ){
       showsection= true;
       return null;
 }
 else if(selresult!='Create Accounts'&& Selresult!='Show Accounts'&& Selresult!='-None-' ){
       return null;
 } else if(selresult!='Create Accounts'&& Selresult!='Delete Accounts'&& Selresult!='Show Accounts' ){
       return null;
 } else
 
 return null;
  }
Replace all these labels with values like: creAcc, none, srchAcc etc

The code will definitely work.


Mark it as BEST ANSWER, if it solves your problem
This was selected as the best answer