function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Ravi Kumar 6740Ravi Kumar 6740 

How to use Wrapper inside wrapper?


You mean something like this?

public class Belege {
        public String Belegnummer {get;set;}
        public String Debitornummer {get;set;}
        public Decimal Bruttobetrag {get;set;}
        public Decimal Nettobetrag {get;set;}
        public Decimal Steuerbetrag {get;set;}
        public Decimal Rabattbetrag {get;set;}
        public List<VKBelegPositionen> VKBelegPositionen {get;set;}

public class VKBelegPositionen {
        public Integer Position {get;set;}
        public String Artikelnummer {get;set;}
        public Decimal Menge {get;set;}
        public Decimal Bruttopreis {get;set;}
        public Decimal Nettopreis {get;set;}
        public String UStKennzeichen {get;set;}
mukesh guptamukesh gupta
Hi Ravi,

Please follow below example:-

In Apex, you can define top-level classes (also called outer classes) as well as inner classes, that is, a class defined within another class. You can only have inner classes one level deep. For example:

if you want to nested then aonther wrapper class should created sapratly
public class AccountSelectClassController{
    //Our collection of the class/wrapper objects wrapClass_1 
    public List<wrapClass_1> wrapAccountList {get; set;}
    public List<Account> selectedAccounts{get;set;}
    public AccountSelectClassController(){
        if(wrapAccountList == null) {
            wrapAccountList = new List<wrapClass_1>();
            for(Account a: [select Id, Name,BillingState, Website, Phone from Account limit 10]) {
                // As each Account is processed we create a new wrapClass_1 object and add it to the wrapAccountList
                wrapAccountList.add(new wrapClass_1(a));
    public void processSelected() {
    selectedAccounts = new List<Account>();
        for(wrapAccount wrapAccountObj : wrapAccountList) {
            if(wrapAccountObj.selected == true) {
    // This is our wrapper/container class. A container class is a class, a data structure, or an abstract data type whose instances are collections of other objects. In this example a wrapper class contains both the standard salesforce object Account and a Boolean value
    public class wrapClass_1 {
        public Account acc {get; set;}
        public Boolean selected {get; set;}
		Public List<wrapClass_2>nestedWrapperList = new List<wrapClass_2>();
        //This is the contructor method. When we create a new wrapAccount object we pass a Account that is set to the acc property. We also set the selected value to false
        public wrapClass_1(Account a) {
            acc = a;
            selected = false;
			 nestedWrapperList.add(new wrapClass_2(pass you object));
		   wrapClass_2 cls2 =  wrapClass_2();

New apex class : wrapClass_2
public class wrapClass_2 {
        public Contact con {get; set;}
        public Boolean selected {get; set;}
        public wrapClass_2(Contact a) {
            con = a;
            selected = false;
if you need any assistanse, Please let me know!!

Kindly mark my solution as the best answer if it helps you.