What is the use of ApexPages.StandardController in the below? What is standard controller salsforce?
What is the use of ApexPages.StandardController in the below? What is standard controller salsforce?
Code
public class myControllerExtension { private final Account acct; public myControllerExtension(ApexPages.StandardController stdController) { this.acct = (Account)stdController.getRecord(); } public String getGreeting() { return 'Hello ' + acct.name + ' (' + acct.id + ')'; } }
Markup
{!greeting}
Standard Controller salesforce objects are automatically provided for standard and all custom objects, bindable to a Visualforce page component with the “standard controller” attribute. It provides a reference to a single/list of record to a set of common actions for data processing and default navigation.
When this VisualForce page is loaded, two controllers have instantiated: the standard controller for an account, and your myControllerExtension. Your VisualForce page can call methods from either of those controllers:
The standardController salesforce offers out-of-the-box operations like save (either create or update) or delete.
Your extension controller can offer custom operations to be performed on the record (in your case, getGreeting).
In order to be able to use the standard operations in the 'standardController', when your extension controller is instantiated, it receives a reference to the standard controller (that's why you need a parameterised constructor).
To clarify: the extension controller is not a child class; it's just another controller class that receives a reference to the standard controller. Hope it helps!