Setter Methods
In Salesforce Apex and Visualforce development, methods in a controller class that receive values from user input on a Visualforce page, following the naming convention set[PropertyName]() for data binding.
Definition
In Salesforce Apex and Visualforce development, methods in a controller class that receive values from user input on a Visualforce page, following the naming convention set[PropertyName]() for data binding.
In plain English
“Setter Methods in Salesforce Apex and Visualforce are controller methods that receive values from user input on a Visualforce page. They follow the naming convention set[PropertyName] and are how Visualforce pages pass user input back to the server-side controller.”
Worked example
A developer at Brackenwell Software writes a Visualforce Custom Controller with a public String inputProductCode property. To support binding from the page's text-input field, she defines a Setter Method: public void setInputProductCode(String value) { this.inputProductCode = value; if(value != null) lookupProduct(); }. The Setter Method runs whenever the Visualforce page passes user input back to the controller - the bound value is set, and her side-effect (the lookupProduct call) fires automatically. Modern Apex's automatic property syntax (public String inputProductCode { get; set; }) generates the equivalent setter implicitly, but the underlying mechanism is the same.
Why Setter Methods matters
In Salesforce Apex and Visualforce development, Setter Methods are methods in a controller class that receive values from user input on a Visualforce page, following the naming convention set[PropertyName]. They're the counterpart to Getter Methods (which send data to the page), forming the two-way binding between Visualforce UI and Apex controllers.
Setter methods are a Visualforce-era concept. Lightning Web Components use different data binding patterns (reactive properties, event-driven communication) that don't use explicit getter/setter methods in the same way. Knowing about setter methods matters for working with Visualforce code and understanding the Visualforce controller model.
How organizations use Setter Methods
Maintains legacy Visualforce controllers using getter/setter patterns.
Trains developers on Visualforce patterns including setter methods for legacy code maintenance.
Uses modern LWC patterns for new development while understanding setters for Visualforce code.
Test your knowledge
Q1. What are Setter Methods?
Q2. What naming convention do they follow?
Q3. What's the modern equivalent?
Discussion
Loading discussion…