• Vamsi Dyana
  • NEWBIE
  • 10 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 1
    Replies
(Total New for Programming...so pls bear with me..thx)
Q:        Create updateOlderAccounts method in Class OlderAccountsUtlity which gets the first five Account records ordered by the date created. It then updates the description field to say that this is a “heritage account,”
Sol:     
  1. Public class OlderAccountsUtility
  2. public static void updateOlderAccounts() {
  3. Account [ ] oldAccounts = [SELECT Id, Description FROM Account ORDER BY CreatedDate ASC LIMIT 5];
  4. for (Account acct : oldAccounts) {
  5. acct.Description = 'Heritage Account';  }
  6. update oldAccounts;  }
I overall get the functioning and output of the method. But have following doubts
*In Line 3 What is the syntax principle – oldAccounts Sobject of type Account is created?right?
Can’t we write this instead-?  
List<Account> oldAccounts=new List<Account>( SELECT Id, Description FROM Account ORDER BY CreatedDate ASC LIMIT 5);
Or
Account[ ] oldAccounts = new List<Account>( SELECT Id, Description FROM Account ORDER BY CreatedDate ASC LIMIT 5);
*In Line5 why to again create acct variable? Can’t we write like this?
  1. for (Account oldAccounts) {
  2. oldAccounts.Description = 'Heritage Account';  }
(Total New for Programming...so pls bear with me..thx)
 
Code under Prerequisite section of Writing SOSL Queries in Apex Basics and Databases 
User-added image

When tried this in Execute Anonymous Window as stated throws this error
User-added image
?
(Total New for Programming...so pls bear with me..thx)
Q:        Create updateOlderAccounts method in Class OlderAccountsUtlity which gets the first five Account records ordered by the date created. It then updates the description field to say that this is a “heritage account,”
Sol:     
  1. Public class OlderAccountsUtility
  2. public static void updateOlderAccounts() {
  3. Account [ ] oldAccounts = [SELECT Id, Description FROM Account ORDER BY CreatedDate ASC LIMIT 5];
  4. for (Account acct : oldAccounts) {
  5. acct.Description = 'Heritage Account';  }
  6. update oldAccounts;  }
I overall get the functioning and output of the method. But have following doubts
*In Line 3 What is the syntax principle – oldAccounts Sobject of type Account is created?right?
Can’t we write this instead-?  
List<Account> oldAccounts=new List<Account>( SELECT Id, Description FROM Account ORDER BY CreatedDate ASC LIMIT 5);
Or
Account[ ] oldAccounts = new List<Account>( SELECT Id, Description FROM Account ORDER BY CreatedDate ASC LIMIT 5);
*In Line5 why to again create acct variable? Can’t we write like this?
  1. for (Account oldAccounts) {
  2. oldAccounts.Description = 'Heritage Account';  }
(Total New for Programming...so pls bear with me..thx)
 
Code under Prerequisite section of Writing SOSL Queries in Apex Basics and Databases 
User-added image

When tried this in Execute Anonymous Window as stated throws this error
User-added image
?