I am trying to create multiple tables based on how many Account Numbers a single Name has, ex) one Name but has 3 different Account Numbers so three tables will be generated with the stocks that each account holds. I have a Visualforce page with nested repeats, and think that it should work but am having trouble with the data in the class. From what I have understood from the docs and other examples is that I want to use an inner class and populate that with the properties like below then use dot notation to assign the values to what I am going to be showing on the table. Let me know if I am doing this correctly.

At the moment I am running into a issue where it says "Variable does not exist: AccountNumber" inside of the for loop. This is not limited to just AccountNumber, all properties I am trying to reference are having the same issue. I have instantiated the object with the properties in the method and from dot notation am trying to assign the values associated with that account number to them.

If anyone could help me figure this out it would be appreciated.

public class PracticeClass {

    class DataDto {

        public String Name { get; set; }
        public String AccountNumber { get; set; }

        public DataDto(String Name, String AccountNumber, List<FinServ__FinancialHolding__c> RowData) {

            this.Name = Name;
            this.AccountNumber = AccountNumber;
            this.RowData = RowData;


    public List<DataDto> getData() {

       List<DataDto> eachTable = new List<DataDto>();

       for(FinServ__FinancialHolding__c id: [SELECT Name,
FROM FinServ__FinancialHolding__c
WHERE FinServ__FinancialAccount__r.Custodian__c = 'Person1' 
AND FinServ__FinancialAccount__r.FinServ__PrimaryOwner__c = :ApexPages.currentPage().getParameters().get('id')])

              eachTable.AccountNumber = id;

       return eachTable;

1 Answer 1


eachTable is a List<DataDto>, not a DataDto. You'll need to make the object inside the loop, like this:

for(sObject record: [your query here]) {
  DataDto recordDto = new DataDto();
  // populate the recordDto variable, then...

I would like to point out that your code has numerous other problems that will prevent compiling. I would recommend starting out small and incrementally building your code. Also, if you plan on having many tables, you should be aware that you are limited to how many queries you can run per transaction, as noted in Execution Governors and Limits.

  • Shouldn't the recordDto still work if it is outside out the loop since it would still be inside of the getData scope? Dec 18, 2023 at 14:56
  • @Unknown_Person The variable can be before the loop, but must be initialized with new DataDto() inside the loop, otherwise you'll just overwrite your data.
    – sfdcfox
    Dec 19, 2023 at 15:58
  • Makes sense, Thanks. Dec 20, 2023 at 16:32

You must log in to answer this question.

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