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
Ankit Bhati 20Ankit Bhati 20 

How to access wrapper class list in another method in lightning

Hi Everone 
I want to access wrapper list in handledelete method but it found null can anyone suggest how to access wrapper in another method. 

public class recordOfAccount {
    @AuraEnabled
    public static List<recAccountChildCls> oRecAccountChildCls{get;set;}
   
    public recordOfAccount(){
        oRecAccountChildCls = new List<recAccountChildCls>();
        system.debug('calling constractor');
    }
    @AuraEnabled
    public static List<recAccountChildCls> recAccount(){
        system.debug('calling');
        Boolean serialNumber = false;
        integer i =0;
        oRecAccountChildCls = new List<recAccountChildCls>();
        List<Account> accountlist = new List<Account>([select id,Name,Phone,Industry from Account limit 100]);
        for(Account oAccount : accountlist){
            oRecAccountChildCls.add(new recAccountChildCls(oAccount,serialNumber));
            i++;
        }
        system.debug('oRecAccountChildCls'+oRecAccountChildCls);
        return oRecAccountChildCls;
        
    }
    @AuraEnabled
    public static void recSave(string nm ,string ph){
        system.debug('name from front end....'+nm);
        system.debug('phone from front end....'+ph);
        Account oAccount = new Account();
        oAccount.Name = nm;    
        oAccount.Phone = ph;
        insert oAccount;
    }
    @AuraEnabled
    public static void handledelete(){
       
        for(recAccountChildCls oAccount : oRecAccountChildCls){
           
            system.debug('oRecAccountChildCls size'+oAccount.srNum);
        }
    }
    public class recAccountChildCls{
        @AuraEnabled
        public Account ac{get;set;}
        @AuraEnabled
        public boolean srNum{get;set;}
        public recAccountChildCls(Account acObj,boolean srNumber){
            ac = new Account();
            ac = acObj;
            srNum = srNumber;
            
            
        }
    }
}
vishal-negandhivishal-negandhi

Hi Ankit, 

ParentClass.WrapperClass is how you can access a wrapper class from outside the main class. Sharing an example code snippet below
 

recordOfAccount.recAccountChildCls wrapperObj = new recordOfAccount.recAccountChildCls(new Account(), true);
Ankit Bhati 1Ankit Bhati 1
HI Vishal

Cann't we access wrapper class in another method  that define in same class like as shown in code.while I am using oRecAccountChildCls in handledelete method it shows null; Could you please elaborate workaroundnd