Salesforce Dictionary — Free Salesforce GlossarySalesforce Dictionary

Custom Controller

Development🔴 Advanced

Definition

A Custom Controller in Visualforce is an Apex class written entirely from scratch that provides all the data and logic for a Visualforce page, without relying on a Standard Controller. Custom Controllers give developers complete control over page behavior, including custom queries, complex business logic, and custom navigation. The custom controller class is specified in the Visualforce page's controller attribute.

Real-World Example

a Salesforce developer at CodeBridge recently implemented Custom Controller to create a robust integration between Salesforce and an external system. Using Custom Controller, the developer builds an efficient solution that syncs data in near real-time, handles error scenarios gracefully, and includes detailed logging for troubleshooting.

Why Custom Controller Matters

A Custom Controller in Visualforce is an Apex class that provides all the data and logic for a Visualforce page without relying on a Standard Controller. Custom Controllers give developers complete control over how data is loaded, how user interactions are processed, and how navigation works. The custom controller class is specified in the Visualforce page's controller attribute, and the page can bind to any public method or property on the class.

Custom Controllers are the right choice when a page has fundamentally different behavior than the Standard Controller provides: aggregating data from multiple objects, integrating with external systems, or implementing complex multi-step workflows. They're more code-intensive than Standard Controllers plus Extensions, which is why Extensions are often the better starting point. But for pages where the Standard Controller model doesn't fit (like a search interface, a dashboard, or a multi-record editor), a Custom Controller gives you the freedom to build what you need.

How Organizations Use Custom Controller

  • CodeBridgeBuilt a Custom Controller for a Visualforce page that aggregates data from Opportunities, Accounts, and a custom Project object into a single view. No Standard Controller would have worked for the cross-object aggregation.
  • TerraForm TechWrote a Custom Controller that orchestrates a multi-step wizard. The controller maintains state across steps through member variables and commits everything to the database only on the final step.
  • Quantum LabsUses Custom Controllers sparingly because Extensions plus Standard Controllers cover most of their needs. The few Custom Controllers they have are well-documented and carefully tested because they're harder to maintain.

🧠 Test Your Knowledge

1. What is a Custom Controller?

2. When is a Custom Controller the right choice?

3. Where is the Custom Controller specified on a Visualforce page?

See something that could be improved?

Suggest an Edit