In Apex, the wrapper class is used to hold different types of data together as a single unit. If a wrapper class contains a list, object, or inner classes, you can access their members using dot notation.
Let's consider an example where you have a wrapper class called MyWrapperClass, which contains a list, an object, and an inner class:
public class MyWrapperClass {
public List<String> stringList;
public MyCustomObject customObject;
public InnerClass inner;
public class MyCustomObject {
public String name;
public Integer value;
}
public class InnerClass {
public String innerField;
}
}
To access the members of the wrapper class, you would follow these steps:
1. Create an instance of the MyWrapperClass:
MyWrapperClass wrapper = new MyWrapperClass();
2. Access the members of the wrapper class using dot notation:
// Accessing the list member
List<String> myList = wrapper.stringList;
// Accessing the custom object member
MyWrapperClass.MyCustomObject obj = wrapper.customObject;
String name = obj.name;
Integer value = obj.value;
// Accessing the inner class member
MyWrapperClass.InnerClass inner = wrapper.inner;
String innerField = inner.innerField;
By using the dot notation, you can access the members of the list, object, and inner class contained within the wrapper class.
Note: Make sure to initialize the wrapper class and its members before accessing them.