Monday, September 17, 2012

How to call PageReference Method on page load

Using "action" attribute of Apex:page tag, we can call a page reference method that will return the new page reference or redirect to the new page.

<apex:page controller="TestController" action="{!checkAndRedirect}"...></apex:page>
Public Class TestController{  
    public PageReference checkAndRedirect()
        // do checks    
        //return new pagereference('/apex/testVisualForcePageName'); //return a new PageReference    
        //       or    
        //return null to go back to the current page  

Note: We cannot return page reference from the constructor.

No comments:

Post a Comment