You need to sign in to do that
Don't have an account?

I am unable to complete Trailhead challenge for "Manipulating records with DML" chapter
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;
}
}
Best recommendation is to spin up a fresh DE for Trailhead exercises so you don't have any conflicting code.
Might be problem with org.
Above code worked for me
If the problem persist check whether you have any account named "My Test Account"
and any cases related. if so delete it and retry.
return newAcc should be in try block .. It should work now ,,
Thank You..
public class AccountHandler {
public static Account insertNewAccount(String a)
{
String aName=a;
Account newAcc = new Account(Name=aName);
try {
insert newAcc;
return newAcc;
}
catch(DMLException e)
{
system.debug('A DML exception has occured' + e.getMessage());
return null;
}
}
}
"You can try this code.it will help you to complete your challenge"
If you find your Solution then mark this as the best answer.
Thank you!
Regards,
Suraj Tripathi