You need to sign in to do that
Don't have an account?
Brandon Brown
Can someone tell me why this won't pass the Trailhead Challenge for Manipulating Records with DML?
Well, all I can say is that it does add an account, and if you send it a blank string, it does return a NULL, so I am wondering what I did wrong. Here is the code:
public class AccountHandler {
public static ID insertNewAccount(String myStr) {
try {
Account acct = new Account(Name=myStr);
insert acct;
return(acct.id);
} catch (DmlException e) {
System.debug('A DML exception has occurred:' + e.getMessage());
return(NULL);
}
}
}
Thanks in advance for the help,
Feeling dumb
public class AccountHandler {
public static ID insertNewAccount(String myStr) {
try {
Account acct = new Account(Name=myStr);
insert acct;
return(acct.id);
} catch (DmlException e) {
System.debug('A DML exception has occurred:' + e.getMessage());
return(NULL);
}
}
}
Thanks in advance for the help,
Feeling dumb
As said in the challenge description, "If the account is successfully inserted, the method should return the account record".
So, replace by
Hope this helps,
Fred
All Answers
As said in the challenge description, "If the account is successfully inserted, the method should return the account record".
So, replace by
Hope this helps,
Fred
Brandon Brown,
Can you help me in this challenge,because i couldn complete this challenge so please help me out.I am sharing my code,please help me out.
public class AccountHandler {
public static Account insertNewAccount(String a) {
system.debug('HEloo' );
try {
Account acct = new Account();
if(a!=null){
acct.name=a;
insert acct;
system.debug('acct'+acct.name);
return acct;
}
else{
acct.name=a;
insert acct;
return null;
}
}
catch (DmlException e) {
System.debug('A DML exception has occurred: ' +e.getMessage());
return null;
}
}
}
Thanks,
Gayathri
For this challenge, I have written below code:
public class AccountHandler {
public static Account insertNewAccount(string str1)
{
try{
Account acct=new Account(Name=str1);
insert acct;
return acct;
}
catch (DMLException e)
{
System.debug('A DML exception has occurred: ' +
e.getMessage());
return (NULL);
}
}
}
This shows 0 compile time error, as well as I got the points for this.
However, when I debug it through, 'Open Execute Anonymus Window' by passing paramter 'AcmeTest' , as shown below.
AccountHandler.insertNewAccount(acmeTest);
It gives error- Line 1, column:33
Variable doesn't exist:acmeTest
what's the reason for it?
Try Because acmeTest is a string representing the Account name.
Hope this helps,
Fred
public class AccountHandler {
public static insertNewAccount(String parameter) {
try {
Account acct = new Account(Name=parameter);
insert acct;
return acct;
} catch (DmlException e) {
System.debug('A DML exception has occurred:' + e.getMessage());
return(NULL);
}
return acct;
}
}
public class AccountHandler {
public static Account insertNewAccount(String AccountName){
// Create the account sObject
Account acct = new Account(Name=AccountName);
// Insert the account by using DML
Database.SaveResult[] saveResultList = Database.insert(acct,false);
}
public class AccountHandler {
public static Account insertNewAccount(String myStr) {
try {
Account acct = new Account(Name=myStr);
insert acct;
system.debug('acct'+acct.name);
return acct;
} catch (DmlException e) {
System.debug('A DML exception has occurred:' + e.getMessage());
return(NULL);
}
}
}