I have a Apex Controller for a VF page. I want to redirect my page to another one, only if I cannot get a specific parameter from the URL. current page: /apex/profile?uname='test;, if i get the null value from the url then it's redirect to /apex/home page.below is my code.
public class HomePageController {
public HomePageController()
{
String unameParam = ApexPages.currentPage().getParameters().get('uname');
if(unameparam == null)
{
// calling logout method to redirect to home page.
Logout();
}
}
public PageReference Logout() {
System.debug('RCHOME ###');
PageReference mainHome= Page.rc_home;
mainHome.setRedirect(true);
return mainHome;
}
if i get the null value from url it's executing Logout()
method successfully but it's not redirecting to home page.
Could you please help on this.