Wrapper Class in Apex Salesforce
In simple words, a wrapper class is a class inside a class. It is also known as a container class. It stores a group of similar or different data type variables into a single object.
Lets understand with an example:
public class ExampleCls {
public class WrapperCls{
public Boolean selected { get; set;}
public String record { get; set;}
}
}
In this example, ExampleCls is the main class and
WrapperCls is the wrapper or the inner class.
This wrapper class contains two different data types,
one Boolean and other one is String
one Boolean and other one is String
Use of Wrapper Class:
- It helps to stores a group of similar or different data type variables into a single object.
- We can use a wrapper class in Lightning Component when we need to send group of data from apex to lightning components.
- We can use Wrapper classes to parse the JSON request and response in REST API.