Newer Version Available
Action Class
You can use ApexPages.Action to create an action method that you can use in a Visualforce custom controller or controller extension.
Namespace
Usage
For example, you could create a saveOver method on a controller extension that performs a custom save.
Instantiation
The following code snippet
illustrates how to instantiate a new ApexPages.Action object that uses the save action:
1ApexPages.Action saveAction = new ApexPages.Action('{!save}');Example
In the following example, when the user updates or creates a new Account and clicks the Save button, in addition to the account being updated or created, the system writes a message to the system debug log. This example extends the standard controller for Account.
The following is
the controller extension.
1public class pageCon{
2 public PageReference RedirectToStep2(){
3 // ...
4 // ...
5 return Page.Step2;
6 }
7}The following is the Visualforce markup for a page that uses the above controller extension.
For information
on the debug log, see “View Debug Logs” in the Salesforce online help.
1<apex:component>
2 <apex:attribute name="actionToInvoke" type="ApexPages.Action" ... />
3 ...
4 <apex:commandButton value="Perform Controller Action" action="{!actionToInvoke}"/>
5</apex:component>
6
7<apex:page controller="pageCon">
8 ...
9 <c:myComp actionToInvoke="{!RedirectToStep2}"/>
10</apex:page>Action Constructors
The following are constructors for Action.
Action(action)
Creates a new instance of the ApexPages.Action class using the specified action.
Signature
public Action(String action)
Parameters
- action
- Type: String
- The action.
Action Methods
The following are methods for Action. All are instance methods.
getExpression()
Returns the expression that is evaluated when the action
is invoked.
Signature
public String getExpression()
Return Value
Type: String
invoke()
Invokes the action.
Signature
public System.PageReference invoke()
Return Value
Type: System.PageReference