• Bob Gillis 7
  • NEWBIE
  • 0 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 2
    Replies
Bob Gillis 7
I am getting "Only top-level class methods can be declared static".  I am missing something simple?

public class AccountHandler {
    public static Account insertNewAccount(String parameter) {
        try {
            Account acct = new Account(Name=parameter);
            insert acct;
            return acct;
            
        } catch (DmlException e) {
            System.debug('A DML exception has occurred:' + e.getMessage());
            return(NULL);
        }
    return acct;
    }
}
 
 
Well, all I can say is that it does add an account, and if you send it a blank string, it does return a NULL, so I am wondering what I did wrong. Here is the code:

public class AccountHandler {

    public static ID  insertNewAccount(String myStr) {
        try {
            Account acct = new Account(Name=myStr);
            insert acct;
            
            return(acct.id);
            
        } catch (DmlException e) {
            System.debug('A DML exception has occurred:' + e.getMessage());
            return(NULL);
        }
        
    }
            
}

Thanks in advance for the help,

Feeling dumb