Experience Salesforce
Controller Extensions Part 2
What You’ll Learn
- What Is Controller Extension In Visualforce?
Topics
- What is Visualforce in Salesforce?
- Architecture of Visualforce Page
- Standard Controller in Visualforce
- How to create View Page in Visualforce?
- How To Create Edit Page In Visualforce?
- Custom Controller in Salesforce
- Getter, Setter Method Part 1
- Getter, Setter Method Part 2
- Apex Page Message in Visualforce
- Controller Extensions Part 1
- Controller Extensions Part 2
- Using Controller Extension with Custom Controller
- Order of Execution
- Tabs in Visualforce
- System Mode in Visualforce
Here’s a sample code example for a Visualforce page with a standard controller and multiple controller extensions in Apex:
Visualforce Page (samplePage.page):
<apex:page controller="Account" extensions="SampleExtension1, SampleExtension2">
<h1>Welcome to the Sample Page</h1>
<apex:outputText value="Account Name: {!accountName}" />
<apex:outputText value="Contact Name: {!contactName}" />
</apex:page>
Controller (SampleController.cls):
public class SampleController {
public String accountName { get; set; }
public SampleController() {
// Initialization logic
accountName = 'ABC Company';
}
}
Controller Extension 1 (SampleExtension1.cls):
public class SampleExtension1 {
private ApexPages.StandardController stdController;
public SampleExtension1(ApexPages.StandardController controller) {
stdController = controller;
}
public String getAccountName() {
// Accessing the standard controller's record
Account acc = (Account)stdController.getRecord();
return acc.Name;
}
}
Controller Extension 2 (SampleExtension2.cls):
public class SampleExtension2 {
private ApexPages.StandardController stdController;
public SampleExtension2(ApexPages.StandardController controller) {
stdController = controller;
}
public String getContactName() {
// Accessing the standard controller's record
Contact con = (Contact)stdController.getRecord();
return con.Name;
}
}
Next Topic
Need Extra Support? Our FREE study materials have got you covered.
Our expert-prepared study materials provide the answers you need. Clear your doubts and improve your skills with detailed notes from industry professionals.