+ Start a Discussion
Anish Mahadik 1Anish Mahadik 1 

Redirect to New VF page for selected picklist value

Hi All,

I have picklist component with 5 (A,B,C,D,E) values. and my requirement is when user select A or B then it will redirect to  the new VF page else it will remain on same page for other Values selection.

Best Answer chosen by Anish Mahadik 1
Sai ThejaSai Theja
Try This

Apex Class:

public class redirectonthebasisonpicklist
public list<selectoption>item{get;set;}
public string picklistvalue{get;set;}
public redirectonthebasisonpicklist()
    item=new list<selectoption>();
    item.add(new selectoption('None','---Select Options---'));
    item.add(new selectoption('NewVFpage1','A)'));   //NewVFpage1 your new page to redirect
    item.add(new selectoption('NewVFpage2','B'));
    item.add(new selectoption('SameVfpage','C'));    // SameVfpage is your current VF page Name
    item.add(new selectoption('SameVfpage','D'));
    item.add(new selectoption('SameVfpage','E'));

public pagereference redirect()
     PageReference pageRef= new PageReference('/apex/'+picklistvalue);
    return pageRef;

VF Page:

<apex:page controller="redirectonthebasisonpicklist" >
 <apex:form >
 <apex:selectList value="{!picklistvalue}" size="1" >
 <apex:selectOptions value="{!item}"/>
 <apex:actionSupport event="onchange" action="{!redirect}" />