0

I am trying to create a custom controller and populate a wrapper class that will be used on a Visualforce page. Two unique values and multiple lists of the holdings. I am getting errors that say "Variable does not exist" for the wrapper properties in the get method. I have tried putting the object being passed inside and outside of the for loop be can still not seem to figure out why.

    public class DataWrapper {
        public String Custodian { get; set; }
        public String AccountNumber { get; set; }
        public List<FinServ__FinancialHolding__c> RowData { get; set; }
 
        public DataWrapper(Account acct, String Custodian, String AccountNumber, List<FinServ__FinancialHolding__c> RowData, Decimal TotalValue) {
            this.Custodian = Custodian;
            this.AccountNumber = AccountNumber;
            this.RowData = new  List<FinServ__FinancialHolding__c>();
        }
    } 

  //Data query
        List<FinServ__FinancialHolding__c> rowData = [SELECT FinServ__FinancialAccount__r.Name, FinServ__FinancialAccount__r.Custodian__c,
                                                        FinServ__FinancialAccount__r.Date_Validated__c, FinServ__FinancialAccount__r.FinServ__FinancialAccountNumber__c, 
                                                        FinServ__Symbol__c, FinServ__Shares__c, FinServ__Price__c, FinServ__MarketValue__c
                                                      FROM FinServ__FinancialHolding__c
                                                      WHERE FinServ__FinancialAccount__r.FinServ__PrimaryOwner__c = :ApexPages.currentPage().getParameters().get('id')
                                                        AND FinServ__FinancialAccount__r.FinServ__FinancialAccountNumber__c IN :strAcctIds];
       
        //Assigning values to properties
       List<DataWrapper> TableData = new List<DataWrapper>();  //outside loop
       
       for(FinServ__FinancialHolding__c id: rowData)
       {     
           //List<DataWrapper> TableData = new List<DataWrapper>();  //inside loop
           
           TableData.AccountNumber.add(id.AccountNumber__c);
           TableData.Custodian.add(id.Custodian__c);
           TableData.RowData.add(id);        
       }
  
 return TableData;
    
2
  • Not 100% sure if this is the issue or not, but you don't get the implicit no-arg constructor if you provide any constructor. So new List<DataWrapper>(); is likely the (or an) issue. If that's the case, then the issue should disappear if you define your own no-arg constructor (in addition to keeping the one you have that takes 5 arguments).
    – Derek F
    Dec 19, 2023 at 15:58
  • @Derek F, Create something similar? i.e. public class DataWrapper { public String Custodian { get; set; } public String AccountNumber { get; set; } public List<FinServ__FinancialHolding__c> RowData { get; set; } } Dec 19, 2023 at 16:09

1 Answer 1

1

You add individual objects to a list, rather than trying to add objects to the elements in the object. For your code to work, you'd have to have a DTO that looks like:

class DataDto {
  List<String> accountNumber = new List<String>();
  List<Id> custodian = new List<Id>();
  // ... etc
}

Which you'd initialize in your main code as:

DataDto TableData = new DataDto();

That's not what you meant to do, presumably.

Instead, you need to create a new individual DTO object inside the loop:

   for(FinServ__FinancialHolding__c id: rowData)
   {     
       DataDto dto = new DataDto();       
       dto.AccountNumber = id.AccountNumber__c;
       // ... etc
       TableData.add(dto);        
   }

Again, I'd recommend that you remove the constructor you've written so you can use the default constructor.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .