function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
ashok dadali 3ashok dadali 3 

Manipulate Record with DML

HI Guys I am triyng to solve this trailhead problem but i am not able to solve pls help me whats is wrong in this programme.

public class AccountHandler {

    public static Account insertNewAccount(String AccountName){

        Account acct = new Account(Name=AccountName);

        try {
            insert acct;

        } catch (DMLException e){
            return null;
        }

        return acct;
    }
}
Vishal Negandhi 16Vishal Negandhi 16
I don't see anything wrong here.. still copying my code for your reference which passed the test. 
 
public class AccountHandler{
    public AccountHandler(){
    }
    
    public Static Account insertNewAccount(String accountName){
        try{
            Account newAccount = new Account(Name = accountName);
            insert newAccount;
            return newAccount;
        }
        catch(Exception e){
            return null;
        }
    }
}

 
Chandra Sekhar CH N VChandra Sekhar CH N V
I'm posting mine which worked for me, I could see a null check for account name
 
public class AccountHandler{
public static Account insertNewAccount(String AccountName){
if(AccountName!=null){
try{
Account acc = new Account();
acc.Name=AccountName;
insert acc;
return acc;
}catch(DMLException e){return null;}
}
else{
return null;
}
}
}