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
sameera gaidhane 6sameera gaidhane 6 

Error for saving: Quick start Apex: Add a method to the class trailhead code


There is problem with my  developer org. A code which is just a copy paste of the code provided in trailhead: Quick start Apex: Add a method to the class. (https://developer.salesforce.com/trailhead/project/quickstart-apex/quickstart-apex-2) is not getting saved.

However we tried this code in my friends org, it got saved and she got the points.User-added image
Best Answer chosen by sameera gaidhane 6
Nethaji BaskarNethaji Baskar
@Samerra,
As per Jitendra Zaa there could be a custom class in your code with name "Account", hence it might be having a conflict... If a class exists with "Account" name, delete it and try saving this new class and method.
https://developer.salesforce.com/forums/?id=906F0000000981XIAQ
Note: Always try to search the Error message, there might be a thread already related to the problem, and a solution available.. which will save your time..   Good Luck

-Nethaji

All Answers

praveen sonepraveen sone
@sameera: there is nothing wrong in the code. Just delete this and recreate another class. try saving it should work. 

These errors may be weird sometimes.
sameera gaidhane 6sameera gaidhane 6
@praveen: I tried by creating a new class from Develop:Apex classes and from dev console both giving the same error.
User-added image
Nethaji BaskarNethaji Baskar
@Samerra,
As per Jitendra Zaa there could be a custom class in your code with name "Account", hence it might be having a conflict... If a class exists with "Account" name, delete it and try saving this new class and method.
https://developer.salesforce.com/forums/?id=906F0000000981XIAQ
Note: Always try to search the Error message, there might be a thread already related to the problem, and a solution available.. which will save your time..   Good Luck

-Nethaji
This was selected as the best answer
sameera gaidhane 6sameera gaidhane 6
Thank you Nethaji :) I had a class named Account due to which it was not working.
Pam LukePam Luke
I am having the same issue. I have a class called "AccountCounter", but not "Account". Could this be interfering with the run? I can't get part two to verify. Thanks.
Starr LimStarr Lim
User-added imageUser-added image

hi all, im facing this issue, have tried deleting and recreated another of the same class but to no avail. have also checked that i've no apex class name.. any idea? :L
 
Michael LippmanMichael Lippman
I'm getting an error message due to the word "void" in line 1 apparently being a problem

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;
}
 
Lindsey Lee HohengartenLindsey Lee Hohengarten
I am getting this same problem. I have made two seperate playgrounds to try it in and have gotten the same error every time. I am just using the clipboard to copy and paste so I am unsure why I am getting this error
Robert RoopRobert Roop
@michael lippman and @lindsey Lee Hohengarten

I believe there is a line of code missing in the code box in the project.

Try this-
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;
    }
}