+ Start a Discussion
URVASHIURVASHI 

Setredirect(true) value passing

Hi can some help.

 

I wana pass a value to a vf page select list but with setredirect as true.

 

I tried using

public PageReference DatabaseSelectionPage() //true tha
 {
       PageReference newpage = new PageReference('/apex/connection1?dbname='+selectedValue);
           newpage.setRedirect(true);
                newpage.getParameters().put('dbname',selectedValue);
         selectedValue=ApexPages.currentPage().getParameters().get(selectedValue);
        
             return newpage;  
    }
   

 But its passing the value in url.

I want my selectedvalue to be passed to my select list on connection1 page.

Can any one please help?

 

Thanks.

Best Answer chosen by Admin (Salesforce Developers) 
sfdcfoxsfdcfox

First of all, your code is overly complicated.

 

public pagereference databaseselectionpage() {
    pagereference newpage = page.connection1;
    newpage.setredirect(true);
    newage.getparameters().put('dbname',selectedValue);
    return newpage;
}

The trick though, is that the next page (connection1) must read that value from the page parameters:

 

    selectedValue = ApexPages.currentPage().getParameters().get('dbname');

 

All Answers

sfdcfoxsfdcfox

First of all, your code is overly complicated.

 

public pagereference databaseselectionpage() {
    pagereference newpage = page.connection1;
    newpage.setredirect(true);
    newage.getparameters().put('dbname',selectedValue);
    return newpage;
}

The trick though, is that the next page (connection1) must read that value from the page parameters:

 

    selectedValue = ApexPages.currentPage().getParameters().get('dbname');

 

This was selected as the best answer
URVASHIURVASHI

Hey sorry i marked it as solution but it isnt working.

My select list still shows the default value.

 

Where do i write the last line of code u have provided.(inside the function or outside)?

 

Thanks

sfdcfoxsfdcfox
It's in the controller for the page you called connection1. You'd place this code in the constructor. selectedValue might not be the correct name; I only used the name because you didn't post the relevant code for the second page.
URVASHIURVASHI

Hey its working fine,when i called it in constructor thanks a lot :):)