Skip to main content
Anudeep Bathini (LTIMindTree) 님이 #Trailhead에 질문했습니다
This is the Challenge:

To pass this challenge, create an Apex class that inserts a new account named after an incoming parameter. If the account is successfully inserted, the method should return the account record. If a DML exception occurs, the method should return null.The Apex class must be called 'AccountHandler' and be in the public scope.

The Apex class must have a public static method called 'insertNewAccount'.

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.

The 'insertNewAccount' method must also accept an empty string, catch the failed DML and return null.

My Class:

public class AccountHandler {

    public static Account insertNewAccount (String accName, Account a) {

         try{   

          a.name = accName;

    

         insert a;

        return a;

        }

        catch(Exception e) {

            return null;

        }

    }    

}

Trailhead class error

Throwing this error, how many times i modified the class.

what is the correct class.?

 
답변 25개
  1. 2015년 6월 16일 오후 12:27
    Following the Bob's advices...

    <code>

    public class AccountHandler {

        public static Account insertNewAccount (String accName){

            

            

        if(accName!=''){    

            try{

                Account a = new Account(Name=accName);

                insert a;

                System.debug('Bravo Andrè! Account created');

                return a;

            } catch(Exception e){

                System.Debug('Account not created');

                return null;

            }

        } else {

            return null;

        }

         

            

        }    

    }

    </code>
0/9000