+ Start a Discussion
Manish Anand 10Manish Anand 10 

Trailhead challenge:Manipulating records with DML

Hi,
For this challenge, I have written below code:

public class AccountHandler {
    public static Account insertNewAccount(string str1)
    {
        try{
        Account acct=new Account(Name=str1);
        insert acct;
        return acct;
         }
        catch (DMLException e)
        {
            System.debug('A DML exception has occurred: ' +
                         e.getMessage());
          return (NULL);
        }
        
    }
}
This shows 0 compile time error, as well as I got the points for this.
However, when I debug it through, 'Open Execute Anonymus Window' by passing paramter 'AcmeTest' , as shown below.
AccountHandler.insertNewAccount(acmeTest);
It gives error- Line 1, column:33
Variable doesn't exist:acmeTest

what I am missing, here?
Best Answer chosen by Manish Anand 10
srlawr uksrlawr uk
When you call 
 
AccountHandler.insertNewAccount(acmeTest);

you need to make your parameter a string, by wrapping it in single quotes:
 
AccountHandler.insertNewAccount('acmeTest');

otherwise I thinks it is a variable name.

All Answers

srlawr uksrlawr uk
When you call 
 
AccountHandler.insertNewAccount(acmeTest);

you need to make your parameter a string, by wrapping it in single quotes:
 
AccountHandler.insertNewAccount('acmeTest');

otherwise I thinks it is a variable name.
This was selected as the best answer
Manish Anand 10Manish Anand 10
Ops my Bad.
srlawr uksrlawr uk
no probs. sometimes it just needs a quick, fresh pair of eyes on things!