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
Tim IhlenfeldTim Ihlenfeld 

Error on "Manipulate Records with DML" Trailhead

Here's the error I'm getting:
"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"

and here is the code I'm using:
public class AccountHandler {
    public static Account insertNewAccount(String accountName){
        try{
            Account newAccount = new Account(Name=accountName);
                insert newAccount;
                return newAccount;

            }
        catch (exception e){
                return null;
            }
    }
}
 
Best Answer chosen by Tim Ihlenfeld
NagendraNagendra (Salesforce Developers) 
Hi Tim,

Sorry for this issue you are encountering.

May I suggest you please try with below piece of code which works fine for me.
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;
    }
}
Hope this helps.

Kindly mark this as solved if the reply was helpful so that it gets removed from the unanswered queue which results in helping others who are encountering a similar issue.

Thanks,
Nagendra
 

All Answers

NagendraNagendra (Salesforce Developers) 
Hi Tim,

Sorry for this issue you are encountering.

May I suggest you please try with below piece of code which works fine for me.
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;
    }
}
Hope this helps.

Kindly mark this as solved if the reply was helpful so that it gets removed from the unanswered queue which results in helping others who are encountering a similar issue.

Thanks,
Nagendra
 
This was selected as the best answer
Tim IhlenfeldTim Ihlenfeld
Thanks for the response, Nagendra. Unfortunately, I continue to get the same error message:

"
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
"
Tim IhlenfeldTim Ihlenfeld
Nagendra, looks like it worked after I tried it in a new playground. My first playground must have gotten corrupted some how.

Thanks for your help!