Wrapper Class
In Salesforce Apex development, a design pattern where a custom class encapsulates (wraps) one or more sObjects or other data types, combining them into a single object for convenient use in Visualforce pages or Lightning components.
Definition
In Salesforce Apex development, a design pattern where a custom class encapsulates (wraps) one or more sObjects or other data types, combining them into a single object for convenient use in Visualforce pages or Lightning components.
In plain English
“A Wrapper Class in Salesforce Apex is a design pattern where a custom class wraps one or more sObjects or data types into a single structure. For example, wrapping a Contact with a boolean 'selected' property for a Visualforce checkbox list. It's a common Apex pattern for combining data.”
Worked example
An Apex developer at Brookmoor Capital builds a Visualforce page showing a list of Contacts with checkboxes for each. Apex doesn't natively let you add a checkbox property to the standard Contact sObject, so the developer creates a Wrapper Class - a custom class with two fields: Contact con; Boolean isSelected; - and instantiates a List<ContactWrapper> for the Visualforce page to bind to. Each wrapper holds one Contact and its associated checkbox state; the Visualforce page renders them as a checkbox-and-row table. Wrapper Classes are the standard Apex pattern for combining sObjects with auxiliary data the page needs.
Why Wrapper Class matters
In Salesforce Apex development, a Wrapper Class is a design pattern where a custom class encapsulates (wraps) one or more sObjects or other data types, combining them into a single structure for processing or display. A classic example is wrapping a record with a boolean 'isSelected' property for checkbox list UIs.
Wrapper classes are a foundational Apex pattern for scenarios where you need to associate additional data with records. They're especially common in Visualforce for UI state (selected/expanded) but the pattern applies broadly in Apex wherever you need to combine related data into one object.
How organizations use Wrapper Class
Teaches wrapper class pattern as foundational Apex design knowledge.
Uses wrapper classes for combining records with UI state.
Applies the wrapper pattern in Apex for data combination scenarios.
Trust & references
Straight from the source - Salesforce's reference material on Wrapper Class.
- Apex ClassesSalesforce Developers
🧠 Test your knowledge
Q1. What is a Wrapper Class?
Q2. What's a classic use case?
Q3. Is it Visualforce-only?

Discussion
Loading discussion…