You need to sign in to do that
Don't have an account?

Redirect visualforce page
Hi friends -
Newbie question.. help please? any of you have the following situation?
When user clicks on the custom link on the home page, depending on the count value the user should be redirected to either page ABC1 or ABC2.
I mean if the count value=0 redirect the page to ABC1 other wise redirect to ABC2
I am trying to achieve this using custom comtroller.
public class MyController
{
List<CustomObject__c > co;
public List<CustomObject__c > getPageName()
{
co=[Select values from CustomObject__c];
Integer count=co.size();
//Please help how to proceed with this part..
if(count ==0)
{
redirect to page ABC1;
}
else
{
redirect to page ABC2;
}
}
}
I'm not sure what your getPageName() method is doing, so I'd just remove it:
public class MyController { List<CustomObject__c> co; public PageReference redirectTest() { co = [Select values from CustomObject__c]; Integer count = co.size(); PageReference myPR = null; if (count == 0) myPR = Page.ABC1; else myPR = Page.ABC2; if (myPR != null) myPR.setRedirect(true); return myPR; } }
And then, pass the redirectTest method as the action on your VF page:
<apex:page controller="MyController" action="{!redirectTest}"> <apex:form> </apex:form> </apex:page>
I haven't run this, but give this a go.
All Answers
Try something like this:
public PageReference redirectTest(Integer count) { PageReference myPR = null; if (count == 0) myPR = Page.ABC1; else myPR = Page.ABC2; if (myPR != null) myPR.setRedirect(true); return myPR; }
Hi friens thanks for the quick reply.
I tried the way as you mentioned below. But no luck
It is not redirecting. When i save the page it is just showing up the same page. It is not redirecting to ABC1 or ABC2.
I checked my query as well it has 2 rows....Please advise. This is very urgent requirement that we have to solve on.....
public class MyController
{
List<CustomObject__c > co;
public List<CustomObject__c > getPageName()
{
co=[Select values from CustomObject__c];
Integer count=co.size();
//Please help how to proceed with this part..
redirectTest(count);
return null;
}
public PageReference redirectTest(Integer count)
{
PageReference myPR = null;
if (count == 0)
myPR = Page.ABC1;
else
myPR = Page.ABC2;
if (myPR != null)
myPR.setRedirect(true);
return myPR;
}
}
Hello
This is how i am referring the controller
<apex:page controller="MyController" > <apex:form> </apex:form> </apex:page>
I'm not sure what your getPageName() method is doing, so I'd just remove it:
public class MyController { List<CustomObject__c> co; public PageReference redirectTest() { co = [Select values from CustomObject__c]; Integer count = co.size(); PageReference myPR = null; if (count == 0) myPR = Page.ABC1; else myPR = Page.ABC2; if (myPR != null) myPR.setRedirect(true); return myPR; } }
And then, pass the redirectTest method as the action on your VF page:
<apex:page controller="MyController" action="{!redirectTest}"> <apex:form> </apex:form> </apex:page>
I haven't run this, but give this a go.
Hi ..
Thanks it worked out pretty good..