You need to sign in to do that
Don't have an account?
Dhairya Shah 15
Having this error:- "Only top-level class methods can be declared static"
<code>
public class AccountHandler{
public static Account insertNewAccount (String accName){
if(accName!=''){
try{
Account a = new Account(Name=accName);
insert a;
System.debug('Bravo User5633! Account created');
return a;
} catch(Exception e){
System.Debug('Account not created');
return null;
}
} else {
return null;
}
}
}
</code>
Challenge Not yet complete... here's what's wrong:
Executing the 'insertNewAccount' method failed. Either the method does not exist, is not static, or does not insert the proper account.
public class AccountHandler{
public static Account insertNewAccount (String accName){
if(accName!=''){
try{
Account a = new Account(Name=accName);
insert a;
System.debug('Bravo User5633! Account created');
return a;
} catch(Exception e){
System.Debug('Account not created');
return null;
}
} else {
return null;
}
}
}
</code>
Challenge Not yet complete... here's what's wrong:
Executing the 'insertNewAccount' method failed. Either the method does not exist, is not static, or does not insert the proper account.
public class AccountHandler{
public static Account insertNewAccount(String accountName){
Account acctToBeInserted = new Account(Name=accountName);
try{
insert acctToBeInserted;
}catch(DMLException e){
System.debug('Inside DMLException catch ,error is ' + e.getMessage());
acctToBeInserted = NULL;
}
return acctToBeInserted;
}
}
Thanks Let me inform if it work :)
Code looks like ok.Make sure that trigger and validation rules are in-active on account.
Give it a try once
Let me know if you have any issues.
Mark it as best answer if it works.
Thanks.
I think you have created AccountHandler as a subclass of another class.Please create it as a seperate class to make it working.
Also use the below steps to create this class
setup->Develop->Apex Classes, Click New
Please refer to the below link for the same:
http://salesforce.stackexchange.com/questions/135865/only-top-level-class-methods-can-be-declared-static
Hope it helps!!
Yes correct it was just an execution problem as i have created static class so have to execute with the class name.
Thanks a lot!!