Skip to main content
2 of 6
added 52 characters in body
SfdcDev14
  • 83
  • 1
  • 4
  • 12

Displaying list returned from method on VF page

I am trying to display the list returned form this method onto a visualforce page but not having any luck. Any help would be appreciated

public List accresults {get;set;}

public List<Account> getAccounts(Integer NumberOfRecords){
        List<Account> accountList = [SELECT Id FROM Account where Status__c = 'Open' Limit 5];
        Map<Id, Account> selectedAccountsMap = new map<Id, Account>();
        Account account;
        List<Account>accResults = new List<Account>();
        Integer rand;
        Integer count = accountList.size();
        //Integer numberOfRecordsToSelect = 25;
        Integer i = 1;

        while (i <= NumberOfRecords){
            rand = randomWithLimit(count);
            System.debug('Random Number: ' + rand);
            account = accountList[rand];

        if(selectedAccountsMap.get(account.Id) == null)
            {
            selectedAccountsMap.put(account.Id, account);

            i++;
                }
        }
            accresults.addAll(selectedAccountsMap.values());
            system.debug(accresults);
            return accresutls;
    }

    public static Integer randomWithLimit(Integer upperLimit){
        Integer rand = Math.round(Math.random()*1000);
        return Math.mod(rand, upperLimit);
    }
SfdcDev14
  • 83
  • 1
  • 4
  • 12