Friday 7 September 2012

Add a Method to Retrieve Account Records - Visualforce


You’re now ready to write getMyAccounts(), which simply returns the list of 10 accounts most recently modified.
  1. Click the MyController tab.
  2. Modify the getMyAccounts() method to read as follows:
    public List<Account> getMyAccounts() {
        return [SELECT Id, Name, AccountNumber FROM Account ORDER BY
               LastModifiedDate DESC LIMIT 10];
    }
  3. Click Save.
Your page now displays the names of the 10 most recently modified accounts. The Visualforce expression {! myaccounts} causes Visualforce to execute yourgetMyAccounts() method in the MyController class. That method returns a list of account records, which is what the <apex:dataList> component iterates over.

No comments:

Post a Comment