Hi,
I used below code to solve this challenge:
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; } } }
But, getting below error. Can anyone please help?
Challenge not yet complete in My Trailhead Playground 1
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
Hi @Varun Pandhi,
it seems that you are returning null twice. Also, the "if" condition is unnecessary. This is the code I used to pass the challenge, check if this helps you:
public class AccountHandler {
public static Account insertNewAccount(String acctName) {
try{ Account acct = new Account(Name= acctName);
// Insert the account by using DML
insert acct;
return acct;
} catch (DMLException exc){
System.debug('DML Exception occured.' +exc.getMessage());
return null;
}
}
}