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 name) {
Account a = new Account();
a.Name = name;
try {
insert a;
} catch (Exception e) {
return null;
}
return a;
}
}
Please accept my solution as Best Answer if my reply was helpful. It will make it available for other as the proper solution. If you felt I went above and beyond, you can give me kudos.
Please see below code
Please accept my solution as Best Answer if my reply was helpful. It will make it available for other as the proper solution. If you felt I went above and beyond, you can give me kudos.
Thanks and Regards
Sandhya
"Try this code,it will complete your challenge." If you find your Solution then mark this as the best answer.
Thank you!
Regards
Suraj Tripathi
public static Account insertNewAccount(String Aname)
{
Account acct = new Account();
System.debug(Aname);
acct.Name=Aname;
try{
insert acct;
} catch (DmlException e) {
System.debug('A DML exception has occurred: ' +
e.getMessage());
return null;
}
return acct;
}
}