SAVE UP to ₹4999/- OFF On All Salesforce Courses Claim Offer

15

Controller Extensions Part 1

What Is Controller Extension In Visualforce?

Extensions are apex classes used to provide addition functionalities to vf page other than controller.

Code Example Of Controller Extension

Here is the below example code for a standard controller extension class

public class SampleExtension {
    private ApexPages.StandardController stdController;
    public SampleExtension(ApexPages.StandardController controller) {
        stdController = controller;
    }
    
    public String getAccountName() {
        // Accessing the standard controller's record
        Account acc = (Account)stdController.getRecord();
        return acc.Name;
    }
}

Here is the below example code for a vf page having a standard controller and extension

public class SampleExtension {
    private ApexPages.StandardController stdController;
    
    public SampleExtension(ApexPages.StandardController controller) {
        stdController = controller;
    }
    
    public String getAccountName() {
        // Accessing the standard controller's record
        Account acc = (Account)stdController.getRecord();
        return acc.Name;
    }
}

salesforce-developer
Next Topic

Need more support?

Get a head start with our FREE study notes!

Learn more and get all the answers you need at zero cost. Improve your skills using our detailed notes prepared by industry experts to help you excel.

Book A 15-Minutes Free Career Counselling Today!