Free Salesforce Developers Tutorials >

Chapter 15 - Visualforce >

Controller Extensions Part 1

Controller Extensions Part 1

What You’ll Learn


S2 Labs

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

Download Study Material

Get access to exclusive study material for Salesforce Certification and ace your exams!

Download Now

Our Salesforce Certification Courses

Hey there! Glad you made it through our Salesforce Developer Training for beginners . But wait! We've got some high-in-demand Salesforce courses for you to take your Salesforce skills to the next level, making you a desired professional in the Salesforce job market.

Post a Comment

Your email address will not be published. Required fields are marked *