I'm trying to debug my method in the Anonymous Windows but I keep getting the infamous Method does not exist or incorrect signature error. The actual error message is: Method does not exist or incorrect signature: void insertNewAccount(String) from the type AccountHandler. Please find below my code snippet.

public class AccountHandler {
 public Account insertNewAccount(String accountName){
        Account accObj = new Account();
        if(accountName != null && accountName != '') {
            accObj.Name = accountName;
             insert accObj;
            //Check if the account has been successfully inserted
            String dbName = [SELECT Name FROM Account WHERE Name=accountName];
            if(dbName == accountName){
                System.debug('Name from db is: ' + dbName);
                return accObj;
            else{ //else something went wrong. The account record was not inserted for whatever reason
               accObj = null;
        return accObj;

This is me calling my method in my debug window:

AccountHandler accObj = new AccountHandler();

To give some context: I am basically adding a new account into Salesforce by giving the account a name that is retrieved through an incoming String parameter. I then insert the record into the database then query it by means of ensuring that it was inserted properly. If the value stored in the Name field matches the one that was supplied in the parameter then that means the insert operation was successful, return the record. Else return null. It is important to note that the return type of my method is of type Account (which is a standard sObject). I thought maybe my method declaration may have been incorrect but again I am not to sure.

1 Answer 1


When I save your apex class, there is an error with saving-

Probably method does not exists on the class and you get an error when executing script from developer console.

To verify look at the code in apex class.

For resolving the error, change below code:

String dbName = [SELECT Name FROM Account WHERE Name=accountName];


// Do mind that when accessing a record, you have to use a list to handle exception. 
//    But for now this may work
String dbName = [SELECT Name FROM Account WHERE Name=:accountName].Name;

Then execute script.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .