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();
accObj.insertNewAccount('LindaTestAccount');
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.