• sooria narayanan Balasubramaniam
  • NEWBIE
  • 10 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 1
    Replies
User-added image

I am trying to insert an account (That is what required of me to complete the challenge). But it throws the error related to "Deletion". FYI, I will furnish the trailhead challenge and the code


Create a method for inserting accounts.
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.


CODE : 
public class AccountHandler {

    public static Account insertNewAccount(String a)
    {
        String aName=a;
        Account newAcc = new Account(Name=aName);
    try {            
            insert newAcc;
        }
        catch(DMLException e)
        {
            system.debug('A DML exception has occured' + e.getMessage());
            return null;
        }    
                return newAcc;
    }
               
}
Hi everyone,
   There is a custom field of type 'checkbox' called "Primary" in Contact object. If this Primary is checked, then the value of the contact's Email field has to be updated in the custom email field named "PrimaryContactEmail"  in the Account Standard object. How can this be done in Trigger. Please do suggest a solution
User-added image

I am trying to insert an account (That is what required of me to complete the challenge). But it throws the error related to "Deletion". FYI, I will furnish the trailhead challenge and the code


Create a method for inserting accounts.
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.


CODE : 
public class AccountHandler {

    public static Account insertNewAccount(String a)
    {
        String aName=a;
        Account newAcc = new Account(Name=aName);
    try {            
            insert newAcc;
        }
        catch(DMLException e)
        {
            system.debug('A DML exception has occured' + e.getMessage());
            return null;
        }    
                return newAcc;
    }
               
}
Hi everyone,
   There is a custom field of type 'checkbox' called "Primary" in Contact object. If this Primary is checked, then the value of the contact's Email field has to be updated in the custom email field named "PrimaryContactEmail"  in the Account Standard object. How can this be done in Trigger. Please do suggest a solution