Extension Class in Salesforce

Extension controllers always have a reference to the main controller passed as an argument to their constructor. In this example, the constructor receives an instance of an ApexPages.StandardController object (If the Visualforce page is using a custom controller, it will receive an instance of an ApexPages.CustomControllerName).


public class StandardControllerExtension {                                                                                                  public StandardControllerExtension(ApexPages.standardController std) { }             }

A common design pattern is to set an instance variable to the Account record you want to rate – the one defined by the parameter passed to the constructor. This variable will be useful in the rest of your controller’s code.

Account acct;
public StandardControllerExtension(ApexPages.standardController std)
acct = (Account)std.getRecord();

Standard controllers include a getRecord() method that returns the record specified in the ID parameter in the page URL. If the URL has no ID parameter, getRecord() returns an initialized object of whichever object type the standard controller references.

Custom Controller

Custom controllers cannot have any arguments passed to their constructor. In the extension controller example, an instance of ApexPages.StandardController is passed to the constructor.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s