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
jitendra singh 172jitendra singh 172 

What is Use of action attribute in <apex:page /> tage ???

What is Use of action attribute in <apex:page /> tage ???
Best Answer chosen by jitendra singh 172
SwethaSwetha (Salesforce Developers) 
The action attribute allows you to take action prior to the page rendering. 

The main use I've found is deciding whether the user should stay on this page or be directed elsewhere.  For example, if a visualforce page overrides a record view for everyone apart from the system administrator, the profile of the user can be checked via merge syntax on the page or via an action method, and if the user is a sysadmin they can be sent elsewhere.  All of this happens before any part of the page is displayed.

This example code snippet uses ‘action’ attribute.This Method is called before page is rendered and allows you to optionally redirect the user to another page.
 
<apex:page controller="Custom Controller" action="{!doActionMethod}" >
    <!--rest of page>
</apex:page >
Controller:
public class CustomController
{
public void doActionMethod()
  {  
    //logic
  }
}
Hope this helps you. Please mark this answer as best so that others facing the same issue will find this information useful.Thank you

All Answers

SwethaSwetha (Salesforce Developers) 
HI Jitendra,
Salesforce provides a way to define logic before rendering a visualforce page by providing a special attribute called as ‘action’. 

Check https://www.greytrix.com/blogs/salesforce/2017/07/20/using-action-attribute-at-vf-page-tag/ that provides code snippet as an example.

Check Bob's answer on the post https://developer.salesforce.com/forums/?id=906F000000098ghIAA for more details.

Hope this helps you. Please mark this answer as best so that others facing the same issue will find this information useful.Thank you
jitendra singh 172jitendra singh 172
Hi Swetha ,
Your provided links are not working , can you explain me it in simple langauge.
SwethaSwetha (Salesforce Developers) 
The action attribute allows you to take action prior to the page rendering. 

The main use I've found is deciding whether the user should stay on this page or be directed elsewhere.  For example, if a visualforce page overrides a record view for everyone apart from the system administrator, the profile of the user can be checked via merge syntax on the page or via an action method, and if the user is a sysadmin they can be sent elsewhere.  All of this happens before any part of the page is displayed.

This example code snippet uses ‘action’ attribute.This Method is called before page is rendered and allows you to optionally redirect the user to another page.
 
<apex:page controller="Custom Controller" action="{!doActionMethod}" >
    <!--rest of page>
</apex:page >
Controller:
public class CustomController
{
public void doActionMethod()
  {  
    //logic
  }
}
Hope this helps you. Please mark this answer as best so that others facing the same issue will find this information useful.Thank you
This was selected as the best answer