Let’s break this down! I’ll explain the difference between a standard controller and a custom controller in Salesforce — it’s a common question for Visualforce development. ?
<apex:page standardController="Account">
<h1>{!Account.Name}</h1>
<apex:form>
<apex:inputField value="{!Account.Phone}"/>
<apex:commandButton value="Save" action="{!save}"/>
</apex:form>
</apex:page>
* This uses the Account standard controller — Salesforce handles loading the record and saving changes automatically!
Example :
Apex Controller :
public class MyCustomAccountController {
public Account acc {get; set;}
public MyCustomAccountController() {
acc = new Account();
}
public PageReference saveAccount() {
insert acc;
return null;
}
}
Visualforce Page :
<apex:page controller="MyCustomAccountController">
<apex:form>
<apex:inputField value="{!acc.Name}"/>
<apex:commandButton value="Save" action="{!saveAccount}"/>
</apex:form>
</apex:page>
* Here, the save logic is handled by the saveAccount method in the custom controller.
public class MyAccountExtension {
private final Account acc;
public MyAccountExtension(ApexPages.StandardController stdController) {
this.acc = (Account)stdController.getRecord();
}
public String getCustomGreeting() {
return 'Hello, ' + acc.Name + '!';
}
}
<apex:page standardController="Account" extensions="MyAccountExtension">
<h1>{!customGreeting}</h1>
</apex:page>
| Feature | Standard Controller | Custom Controller |
|---|---|---|
| CRUD Operations | Automatic | Manual (you write the logic) |
| Business Logic | Limited | Fully customizable |
| Security Enforcement | Enforced automatically | Must handle manually |
| Multiple Objects | No | Yes |
| Ease of Use | Simple, quick to set up | More effort, but flexible |