Tuesday, April 5, 2011

Salesforce: controller methods(Action,Getter,Setter)

Visualforce markup can use the following types of controller extension and custom controller methods:

1)Action
2)Getter
3)Setter

Action Methods

Action methods perform logic or navigation when a page event occurs, such as when a user clicks a button, or hovers over an area of the page. Action methods can be called from page markup by using {! } notation in the action parameter of one of the following apex tags:
1)commandButton - creates a button that calls an action
2)commandLink - creates a link that calls an action
3)actionPoller- periodically calls an action
4)actionSupport- makes an event (such as “onclick”, “onmouseover”, and so on) on another, named component, call an action
5)actionFunction- defines a new JavaScript function that calls an action
6)page - calls an action when the page is loaded
For example, in the sample page in Building a Custom Controller, the controller's save method is called by the action parameter of the tag. Other examples of action methods are discussed in Defining Action Methods.

Getter Methods
Getter methods return values from a controller. Every value that is calculated by a controller and displayed in a page must have a corresponding getter method, including any Boolean variables. For example, in the sample page in Building a Custom Controller, the controller includes a getAccount method. This method allows the page markup to reference the account member variable in the controller class with {! } notation. The value parameter of the tag uses this notation to access the account, and dot notation to display the account's name. Getter methods must always be named getVariable.

Setter Methods
Setter methods pass user-specified values from page markup to a controller. Any setter methods in a controller are automatically executed before any action methods.

Setter methods must always be named setVariable.

More Information

2 comments:

Unknown said...

CAN YOU PLZ SOLVE MYPROBLEM??

public class mySecondController {
Account account;
public Account getAccount() {
if(account == null) account = new Account();
return account;
}
public PageReference save() {
// Add the account to the database.
insert account;
// Send the user to the detail page for the new account.
PageReference acctPage = new ApexPages.StandardController(account).view();
acctPage.setRedirect(true);
return acctPage;
}
}



Error: Illigal assignment from system.pagereference to pagereference

Unknown said...

On the place of this---

PageReference acctPage = new ApexPages.StandardController(account).view();

Use this----

PageReference acctPage = new ApexPages.StandardController(account);
acctPage.view();