You need to sign in to do that
Don't have an account?

Method does not exist or incorrect signature: void insertNewAccount(String) from the type anon
This is what my code is suppose to be doing:
To pass this challenge, create an Apex class that inserts a new account named after an incoming parameter. If the account is successfully inserted, the method should return the account record. If a DML exception occurs, the method should return null.
public class AccountHandler {
public static Account insertNewAccount(String accName){
if(accName!=''){
try{
Account a = new Account(Name=accName);
insert a;
return a;
} catch(Exception e){
return null;
}
} else {
return null;
}
}
}
When I test it inside of the execute anonymous window, I input "insertNewAccount('abcd');". I get an error saying "Method does not exist or incorrect signature: void insertNewAccount(String) from the type anon"
To pass this challenge, create an Apex class that inserts a new account named after an incoming parameter. If the account is successfully inserted, the method should return the account record. If a DML exception occurs, the method should return null.
public class AccountHandler {
public static Account insertNewAccount(String accName){
if(accName!=''){
try{
Account a = new Account(Name=accName);
insert a;
return a;
} catch(Exception e){
return null;
}
} else {
return null;
}
}
}
When I test it inside of the execute anonymous window, I input "insertNewAccount('abcd');". I get an error saying "Method does not exist or incorrect signature: void insertNewAccount(String) from the type anon"
All Answers
This was a problem for a trailhead module. I am pretty sure the above code is fine, but my trailhead says "There was an unexpected error in your org which is preventing this assessment check from completing: System.NullPointerException: Attempt to de-reference a null object"
As you insertNewAccount method is static so you need to call like below
CLASSNAME.MethodName('Data');
Can you please let me for which module you are talking about
This is module
The program is showing error while executing as you are declaring your insertNewAccount method
as static. Static methods cannot be called directly by their name they need to be called through class name.
All you need to do is:
AccountHandler.insertNewAccount('accountName');
Use this and your program will surely run.
Hope you find this solution helpful, please mark it as best answer if you get help from it.
Thanks.
Ajay Dubedi