• Ashish_Pandey
  • NEWBIE
  • 15 Points
  • Member since 2016
  • Salesforce Developer


  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 3
    Replies
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.
User-added image
public class AccountHandler {
    public static Account insertNewAccount (String acName){
    if(acName!=''){    
        try{
            Account a = new Account(Name=acName);
            insert a;
            System.debug('Account created');
            return a;
        } catch(Exception e){
            System.Debug('Account not created');
            return null;
        }
    } else {
        return null;
    }
     
        
    }    
}

 
Hello,

I'm going through the Formulas & Validations module and I'm stuck with the challenge on the "Creating Validation Rules".
I'm getting this 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.DmlException: Insert failed. First exception on row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, Contact must be in Code of the account: [MailingPostalCode]
 
Hi,
I have the field name and I need to find the object to which it belongs to?
example:
field name: Status
I need to find the object to which this field belongs?
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.
User-added image
public class AccountHandler {
    public static Account insertNewAccount (String acName){
    if(acName!=''){    
        try{
            Account a = new Account(Name=acName);
            insert a;
            System.debug('Account created');
            return a;
        } catch(Exception e){
            System.Debug('Account not created');
            return null;
        }
    } else {
        return null;
    }
     
        
    }    
}