Salesforce Dictionary - Free Salesforce GlossarySalesforce Dictionary
DictionaryWWrapper Class
DevelopmentIntermediate

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.

§ 01

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.

§ 02

In plain English

👋 Study buddy

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.

§ 03

Worked example

scenario · real-world use

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.

§ 04

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.

§ 05

How organizations use Wrapper Class

CodeBridge

Teaches wrapper class pattern as foundational Apex design knowledge.

Quantum Labs

Uses wrapper classes for combining records with UI state.

TerraForm Tech

Applies the wrapper pattern in Apex for data combination scenarios.

§

Trust & references

Official documentation

Straight from the source - Salesforce's reference material on Wrapper Class.

Was this entry helpful?
Help us write better definitions. Quick reactions or detailed edit suggestions.
§

🧠 Test your knowledge

Q1. What is a Wrapper Class?

Q2. What's a classic use case?

Q3. Is it Visualforce-only?

§

Discussion

Loading…

Loading discussion…