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
AnshulJainAnshulJain 

Redirecting to different Visualforce Page

Hi,

I have a requirement for which i need to perform an action in apex:page tag. NOw i am trying to use an action in Apex:command Button. But now when i click the button its again calling the function mentioned in apex:page action.

 

please refer what i am trying to do in the page. and if anyone has a solution please post. it would be of great help.

 

<apex:page standardController="Account" action="{!doCustomDisplayChk}" extensions="AccControllerExtension">
    <apex:pageMessages />
    <p/>
    <apex:form id="theForm">
     
        <apex:pageBlock title="Client & Prospect Detail" mode="maindetail" id="pageBLOCK">
            <apex:pageBlockButtons id="buttons" >
                <apex:commandButton id="StandardView" action="{!saveIT}"  value="Standard View1" >
            </apex:pageBlockButtons>

        </apex:pageBlock>
    </apex:form>

</apex:page>

Naidu PothiniNaidu Pothini

If you dont mind can you post your controller class?

Gunners_23Gunners_23

Its because of the order in which it runs when the page loads. When ever the page loads it first runs the constructor and

 

then the action method in <apex:page>. Inorder to stop from being happening you need to remove action attribute from the

 

<apex:page>

AnshulJainAnshulJain

Hi, Thanks for the quick reply.

 My requirement is that i want to decide on the page load which page to call. So i have to use action method with page tag to redirect the page. Because we cant redirect to another page using controller. As controllers has no return type.

 

I have a work around for this. we can have different visualforce pages. First page will decide if i need to redirect to the same page or other and in the main page we can perform our commondButton method.

If any one has any better idea please let me know to decrease my SLA.

 

Below is my controller class.

 

 public AccControllerExtension(ApexPages.StandardController acon)
    { 

     /// code

  }

public PageReference doCustomDisplayChk()
    {
        Id id = ApexPages.currentPage().getParameters().get('id');
        User userObj = [SELECT Account_Custom_Display__c from User where Id = :UserInfo.getUserId() ];
        PageReference pageRef = new PageReference('/apex/AccountCustomDisplay');
       
        if (userObj.Account_Custom_Display__c == false)
        {
            String partialUrl = '/' + id + '?nooverride=1';
            pageRef = new PageReference(partialUrl);
            pageRef.setRedirect(false);
       
            
        }
        return pageRef;
        
    }