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

Stuck with working on Challenge for Manipulating Records with DML section
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.
The Apex class must be called 'AccountHandler' and be in the public scope.
The Apex class must have a public static method called 'insertNewAccount'.
The 'insertNewAccount' method must accept an incoming string as a parameter, name the account after the parameter, insert it into the system and then return the account record.
The 'insertNewAccount' method must also accept an empty string, catch the failed DML and return null.
Getting following Error message :
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.
Following is the Code written for this ,any help is appreciated to complete the challenge
//
Public class AccountHandler{
public static List<Account> insertNewAccount(String firstname){
Account a=new Account();
a.Name=firstname;
insert a;
List <Account> queriedaccoutn = [SELECT Name
FROM Account
WHERE Name =:firstname
LIMIT 1];
return queriedaccoutn;
}
}
//
Thanks
Amit Chaudhary
All Answers
Thanks
Amit Chaudhary
public with sharing class AccountHandler {
public static Account insertNewAccount (Name strName){
Account acct = new Account();
if(strName != null){
acct.Name = strName;
try {
upsert acct;
return acct;
}
catch (DmlException e) {
System.debug('A DML exception has occurred: ' +
e.getMessage());
return(null);}
}
else
return null;}
}