Definition
A Controller (Visualforce) is an Apex class that provides the data, business logic, and navigation behavior for a Visualforce page. There are three types: Standard Controllers (provided automatically for each object, handling basic CRUD operations), Custom Controllers (entirely custom Apex classes), and Controller Extensions (Apex classes that add to a standard or custom controller). The controller determines what data the page can access and how user interactions are processed.
Real-World Example
Consider a scenario where a developer at Quantum Labs is working with Controller, Visualforce to build a custom solution that extends the platform beyond its standard capabilities. They write clean, bulkified code for Controller, Visualforce, add comprehensive test coverage, and deploy it through a CI/CD pipeline. The new functionality handles 10,000 records without hitting governor limits.
Why Controller, Visualforce Matters
A Controller in Visualforce is the Apex class that supplies data, business logic, and behavior to a Visualforce page. Salesforce supports three controller patterns: Standard Controllers are automatically provided for each standard and custom object, handling basic record loading, Save, and Cancel operations for free. Custom Controllers are Apex classes you write entirely yourself, giving you full control over page behavior. Controller Extensions sit between the two, adding custom logic on top of a Standard or Custom Controller without replacing it.
The choice between these patterns comes down to how much customization you need. If the page mostly does standard record operations with a few tweaks, a Standard Controller plus an Extension is usually the cleanest approach. If the page has fundamentally different behavior (like aggregating data from multiple objects or integrating with external systems), a Custom Controller is often necessary. In all cases, controllers should follow the same quality practices as any Apex code: explicit sharing declarations, unit test coverage, and separation of business logic from controller wiring.
How Organizations Use Controller, Visualforce
- •Quantum Labs — Uses Standard Controllers with Extensions for 90% of their Visualforce pages. The remaining 10% are Custom Controllers for pages that aggregate data across multiple objects and don't fit the Standard Controller model.
- •CodeBridge — Built a review checklist for Visualforce Controllers that covers sharing declarations, bulk-safe query patterns, and test coverage. The checklist catches quality issues before they reach production.
- •TerraForm Tech — Refactored a Custom Controller into a Standard Controller plus Extension during a cleanup project. The refactor reduced the Apex code by 60% and made the page easier to maintain.
