• denis panou
  • NEWBIE
  • 0 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies
Hi all.Sorry for questions but i really dont understand what i do wrong
i try finish Apex Basic module
and stop in third episode

thats text of 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.

that's my code

public class AccountHandler {
    
     public static String insertNewAccount(String str) {
         try {

        Account acct = new Account(Name=str);
        insert acct;
             } catch (DmlException e) {
    System.debug('A DML exception has occurred: ' + e.getMessage()); 
    return null;
     }
      return str;             
    }
}

in my logic it must works, but it failed and i don't know why, please help me, what's wrong in my code?
Hi all.Sorry for questions but i really dont understand what i do wrong
i try finish Apex Basic module
and stop in third episode

thats text of 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.

that's my code

public class AccountHandler {
    
     public static String insertNewAccount(String str) {
         try {

        Account acct = new Account(Name=str);
        insert acct;
             } catch (DmlException e) {
    System.debug('A DML exception has occurred: ' + e.getMessage()); 
    return null;
     }
      return str;             
    }
}

in my logic it must works, but it failed and i don't know why, please help me, what's wrong in my code?