function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Jeffrey Rheel 1Jeffrey Rheel 1 

Trailhead Add a "Method to the class" not working

Well this is odd...I'm doing a very simple Apex module and just copy / paste code, save and then error on Verify Step.

I tried this in 2 orgs and received the same error.  I even went onto the next steps that run the code and those passed but this one didn't.

Thoughts?

User-added image
Best Answer chosen by Jeffrey Rheel 1
Lokesh KumarLokesh Kumar
Hi, Jeffery Issue is you have to copy the method to the class that already created "OlderAccountsUtility" in the first step of the same module.

PFB Working Code.
public class OlderAccountsUtility {
 public static void updateOlderAccounts() {
    // Get the 5 oldest accounts
    Account[] oldAccounts = [SELECT Id, Description FROM Account ORDER BY CreatedDate ASC LIMIT 5];
    // loop through them and update the Description field
    for (Account acct : oldAccounts) {
        acct.Description = 'Heritage Account';
   }
   // save the change you made
   update oldAccounts;
}

}
Happy Coding !!

Thanks 

 

All Answers

Lokesh KumarLokesh Kumar
Hi, Jeffery Issue is you have to copy the method to the class that already created "OlderAccountsUtility" in the first step of the same module.

PFB Working Code.
public class OlderAccountsUtility {
 public static void updateOlderAccounts() {
    // Get the 5 oldest accounts
    Account[] oldAccounts = [SELECT Id, Description FROM Account ORDER BY CreatedDate ASC LIMIT 5];
    // loop through them and update the Description field
    for (Account acct : oldAccounts) {
        acct.Description = 'Heritage Account';
   }
   // save the change you made
   update oldAccounts;
}

}
Happy Coding !!

Thanks 

 
This was selected as the best answer
Jeffrey Rheel 1Jeffrey Rheel 1
Yeah, figured it had to be something simple like that.  Always good to have a second set of eyes looking at it.  Thanks!
Bhushan WarjurkarBhushan Warjurkar
Thank you!