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
renuamirenuami 

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;

}

}

}

Best Answer chosen by Admin (Salesforce Developers) 
J&A-DevJ&A-Dev

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

J&A-DevJ&A-Dev

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; }

 

 Then in your redirect portion, just call the above method and pass the count.

 

renuamirenuami

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;
}

}


 


 

 

 

Message Edited by renuami on 04-02-2009 10:53 AM
J&A-DevJ&A-Dev
Could you post the portion of your code that shows how you reference the controller?
renuamirenuami

Hello

 

This is how i am referring the controller

 

 

<apex:page controller="MyController" > <apex:form> </apex:form> </apex:page>

 


 

Message Edited by renuami on 04-02-2009 12:48 PM
J&A-DevJ&A-Dev

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.

 

 

 

This was selected as the best answer
renuamirenuami

Hi ..

 

Thanks it worked out pretty good..