You need to sign in to do that
Don't have an account?
rachel watson
Trailhead- Manipulating Records with DML
I am new to coding and do not have a background with OO languages. I am trying to pass the Manipulating Records with DML module and keep getting errors. Please help.
The following is my 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');
}
}
}
I am receiving these 2 errors in line 2:
unexpected token: 'List'
Method must define a body
The following is my 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');
}
}
}
I am receiving these 2 errors in line 2:
unexpected token: 'List'
Method must define a body
Hi Rachel,
The problem is you have put a ';' in the line 2. please try after removing the semicolon.
Please let me know if this helped you.
Thanks!
public class AccountHandler {
public static ID insertNewAccount(String MyStr) ; { //The semicolon here is what I am refering to.
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!
return null;
instead of:
Return('NULL');
Please try with below code :
Let me know if you have any issue.
Thanks,
Abhishek
Sorry I missed the return statement in try block.
return (acct.id);
should be:
return acct.id; //without the brackets
I have corrected the code. Please try this:
Thanks!