+ Start a Discussion
Ravi Kumar 259Ravi Kumar 259 

when u used extension controller? why we go for this even we have above.?

PratikPratik (Salesforce Developers) 
Hi Ravi,

Extension is usually used from a reusbale code perspective. If i have some functionality in one class and i want to use it somewhere else also then instead of coding that part, you can add an extension to the controller and reuse the code used in extension class.

Thanks,
Pratik
Amit Chaudhary 8Amit Chaudhary 8
Standard Controller
to associate a page with the standard controller for a custom object named MyCustomObject, use the following markup
<apex:page standardController="MyCustomObject__c">
</apex:page>
Extension

Standard controllers can provide all the functionality you need for a Visualforce page because they include the same logic that is used for a standard page. For example, if you use the standard Accounts controller, clicking a Save button in aVisualforce page results in the same behavior as clicking Save on a standard Account edit page.

Page:-
<apex:page standardController="Account" extensions="myControllerExtension">
</apex:page>
Class:-
public class myControllerExtension {
   private final Account acct;
    public myControllerExtension(ApexPages.StandardController stdController) {
        this.acct = (Account)stdController.getRecord();
    }
}


https://developer.salesforce.com/page/Building_Visualforce_Pages_Using_the_Standard_Controller
https://www.salesforce.com/docs/developer/pages/Content/pages_controller_std_associate.htm
https://www.salesforce.com/docs/developer/pages/Content/pages_controller.htm