1
  1. The Apex class must be called 'AccountHandler' and be in the public scope.
  2. The Apex class must have a public static method called 'insertNewAccount'.
  3. 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.
  4. The 'insertNewAccount' method must also accept an empty string, catch the failed DML and return null.
public class AccountHandler {
    public static Account insertNewAccount(String name) {
        Account a = new Account();
        a.Name = name;
        try {
            insert a;
            return a;
        } catch (Exception e) {
            return NULL;
        }
    }
}

SHOWING ERROR:

Challenge Not yet complete... here's what's wrong: 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

1
  • 2
    You can check the debug logs if you face exception when attempting a trailhead challenge.
    – C0DEPirate
    Jul 30, 2017 at 10:30

2 Answers 2

1

Small correction is needed in your code.Try the below code:

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;
    }
}
0

Everything looks correct in your code. There might be some problem in the Trailhead unit, or some other code you didn't post.

I see you're trying to do this Trailhead. https://trailhead.salesforce.com/en/modules/apex_database/units/apex_database_dml

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .