• Amit Shrivastava
  • NEWBIE
  • 9 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 3
    Replies
Hi

While attempting this challenge, I am not able to pass it after verifying this challenge, based on the challenge details I have to write following pice of code which is totally correct, but still, it gave me an error to check code.
 
public class AccountHandler {
    
    public static Account insertNewAccount(string acctName){
      Account acct = null;
        try {
             acct = new Account(Name=acctName);
            insert acct;
            return acct;
        }
        catch (DmlException e) {
            System.debug('A DML exception has occurred: ' +
                e.getMessage());
        }
         return acct;
    }
}
but after correcting this error, I need to write following code to pass this challenge
public class AccountHandler {
    
    public static Account insertNewAccount(string acctName){
      
        try {
             Account acct = new Account(Name=acctName);
            insert acct;
            return acct;
        }
        catch (DmlException e) {
             return null;
        }
    }
}
Can anyone let me know what wrong with the first code snippet, is it due to the System.Debug statement in the catch block? or is it completely checking the return type in a catch block? 
 
Hi

While attempting this challenge, I am not able to pass it after verifying this challenge, based on the challenge details I have to write following pice of code which is totally correct, but still, it gave me an error to check code.
 
public class AccountHandler {
    
    public static Account insertNewAccount(string acctName){
      Account acct = null;
        try {
             acct = new Account(Name=acctName);
            insert acct;
            return acct;
        }
        catch (DmlException e) {
            System.debug('A DML exception has occurred: ' +
                e.getMessage());
        }
         return acct;
    }
}
but after correcting this error, I need to write following code to pass this challenge
public class AccountHandler {
    
    public static Account insertNewAccount(string acctName){
      
        try {
             Account acct = new Account(Name=acctName);
            insert acct;
            return acct;
        }
        catch (DmlException e) {
             return null;
        }
    }
}
Can anyone let me know what wrong with the first code snippet, is it due to the System.Debug statement in the catch block? or is it completely checking the return type in a catch block? 
 
Hi

While attempting this challenge, I am not able to pass it after verifying this challenge, based on the challenge details I have to write following pice of code which is totally correct, but still, it gave me an error to check code.
 
public class AccountHandler {
    
    public static Account insertNewAccount(string acctName){
      Account acct = null;
        try {
             acct = new Account(Name=acctName);
            insert acct;
            return acct;
        }
        catch (DmlException e) {
            System.debug('A DML exception has occurred: ' +
                e.getMessage());
        }
         return acct;
    }
}
but after correcting this error, I need to write following code to pass this challenge
public class AccountHandler {
    
    public static Account insertNewAccount(string acctName){
      
        try {
             Account acct = new Account(Name=acctName);
            insert acct;
            return acct;
        }
        catch (DmlException e) {
             return null;
        }
    }
}
Can anyone let me know what wrong with the first code snippet, is it due to the System.Debug statement in the catch block? or is it completely checking the return type in a catch block? 
 
When attempting to create my Apex trigger for this Trailhead development exercise, I receive an error. I don't understand how this is possible, because the records haven't been updated, and still aren't updating.
"Challenge not yet complete... here's what's wrong:
Setting 'Match_Billing_Address__c' to false updated the records anyway. The trigger should only act when Match_Billing_Address__c is true."


Here's my code:
trigger AccountAddressTrigger on Account (before insert, before update) {

    for(Account a : Trigger.new){
        If (a.Match_Billing_Address__c = true) {
            a.ShippingPostalCode = a.BillingPostalCode;
        }   
    }

}