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
Carly CrandallCarly Crandall 

Manipulating Records with DML Challenge issue

Hi everyone,
  So below is my code. I usually program in java so I thought that this would be somewhat self explanitory but I am running into some issues! My first is that when I put this code and try to execute this for the DML challenge issue it will not pass and I get the 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.


My code looked fine to me and I even modified it so it looked pretty much identical as some others on this forum. The other thing that I do not understand is how do I execute the code even! Just to test it and see if it works. 

public class AccountHandler {
    public static Account insertNewAccount(String accName){
        
        
    if(accName!=''){    
        try{
            Account a = new Account(Name=accName);
            insert a;
            System.debug('The account has been created, congrats.');
            return a;
        } catch(Exception e){
            System.Debug('Account has not created');
            return null;
        }
    } else {
        return null;
    }
     
        
    }    

}

Thanks Much, 
Carly C
Best Answer chosen by Carly Crandall
sfdcMonkey.comsfdcMonkey.com
hi Carly
delete your class once and recreate with below code
public class AccountHandler {
public static Account insertNewAccount(String s)
{
     Account act = New Account();
        act.Name = s;
    try {
  
        insert act;
        }
    catch (DmlException e) {

	   return null;
                           }
    return act;
}
}
for check this go to developer console Open Execute Anonymous Window or CTRL+E.
enter below lines

system.debug(AccountHandler.insertNewAccount('Test'));

check open log checkbox and click on execute button 
after open log find your log
User-added imageUser-added image
I hop it helps you
Mark it best answer if it helps you so it make proper solution for others :)
thanks

 

All Answers

Dilip_VDilip_V
Carly,

code looks good.
However give it a try
Public class AccountHandler
{
    public static Account insertNewAccount(String acc)
    {
        Account acct = new Account(name=Acc);
        //Database.insert(acct, false);
        try{
            insert Acct;
        }
        Catch(Exception e){
            return null;
        }
        return Acct;
    }
}

Let us know if it works.

If it works mark it as best answer.

Thanks.
 
sfdcMonkey.comsfdcMonkey.com
hi Carly
delete your class once and recreate with below code
public class AccountHandler {
public static Account insertNewAccount(String s)
{
     Account act = New Account();
        act.Name = s;
    try {
  
        insert act;
        }
    catch (DmlException e) {

	   return null;
                           }
    return act;
}
}
for check this go to developer console Open Execute Anonymous Window or CTRL+E.
enter below lines

system.debug(AccountHandler.insertNewAccount('Test'));

check open log checkbox and click on execute button 
after open log find your log
User-added imageUser-added image
I hop it helps you
Mark it best answer if it helps you so it make proper solution for others :)
thanks

 
This was selected as the best answer
Carly CrandallCarly Crandall
Thanks Much,
fixed all my problems 
 
Orquidea Perez 18Orquidea Perez 18
I'm having the same problem, I have tried using other peoples recommendations (code) and it still won't let me pass the challenge

"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"

Here is the snippet of code I am using:

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

}