function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
ChinnoduChinnodu 

Hi All,what kind of situation we are using extension controller?

Hi ,
what kind of situation we are using extension controller? when we will use give me with best example.


Regards,
Viswa
reymagdaongreymagdaong
Hi,
Basically if you want to extend or Add more functionality to the standardcontroller methods (save, cancel, etc). One example i can give is that if you are building a VF Page that can save multiple child records of a parent record (standard contrller). you will have to have an extension controller that creates/and saves that child records.
Amit Chaudhary 8Amit Chaudhary 8
Building a Controller Extension:-
A controller extension is any Apex class containing a constructor that takes a single argument of typeApexPages.StandardController or CustomControllerName, where CustomControllerName is the name of a custom controller you want to extend
https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_controller_extension.htm
public class myControllerExtension {

    private final Account acct;
    
    // The extension constructor initializes the private member
    // variable acct by using the getRecord method from the standard
    // controller.
    public myControllerExtension(ApexPages.StandardController stdController) {
        this.acct = (Account)stdController.getRecord();
    }

    public String getGreeting() {
        return 'Hello ' + acct.name + ' (' + acct.id + ')';
    }
}

What are Custom Controllers and Controller Extensions?
https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_controller_def.htm

Considerations for Creating Custom Controllers and Controller Extensions
https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_controller_considerations.htm
http://salesforce.stackexchange.com/questions/4041/difference-between-controller-and-extensions
http://www.salesforcetutorial.com/custom-controllers-controller-extensions/