Skip to main content
6 of 6
deleted 138 characters in body
SfdcDev14
  • 83
  • 1
  • 4
  • 12

Displaying list returned from method on VF page

public List<Account> 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 accresults;
}

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