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
VFVF 

issue in constructor method

In my class i have a constructor here i am calling  a method in the constructor so as to  redirect to another Vf page.

Here is the code:

class:

 public class MyClass

{

   public MyClass(ApexPages.StandardController controller)

    {    

  ShowDetails(); 

    }

 

  public PageReference ShowDetails()

   {

   return page.MyPage; 

 

   } 

 

 

 

is there any thing wrong in the code.Help me out guyz

 

Thanks shaan 

wesnoltewesnolte

Hey

 

No navigation would occur because constructors return void. You can call you method from the action method of <apex:page> though.

 

Cheers,

Wes 

VFVF

Thanks for ur reply.

I know about the action method but would like to navigate using constructor. 

can i navigate using a void method from one page to another???

 

 

wesnoltewesnolte

Unfortunately not. Action methods that return pageReferences or URLFOR in an action attribute are your direct options.

 

Wes

VFVF

Thanks again wes.

My problem is that i am opening a VF page when clicked on a VF tab.

In  that page i am displaying the custom object details in the page. 

Before the page is opened i am checking a condition .

The condition is :

if(objectList.size() >0)

{

display values.......... 

else

{

redirect to New page..... 

 

is there any solution  for this with u?? 

wesnoltewesnolte

Hey

 

Ah I see your problem now;) I've done a very brief test and this compiles

 

action="{!IF(true,null,null)}"

 

I'm not sure if it will work though. Try changing it to suit your needs, eg.

 

action="{!IF(methodToCheckSize,null,ShowDetails)}"

 

Hope that works,

Wes

PG1978PG1978

did you ever sloved it? i am also running into same issue.