function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Vinicius DamascenoVinicius Damasceno 

Create a method for inserting accounts. Line: 1, Column: 32 Unexpected token '('.

Someone can tell me why im getting this error? Its seems a good code for me.

public class AccountHandler {
    public static Account insertNewAccount (String Nome){
        try
        {
               Account acct = new Account();
            acct.Name = Nome;
            insert acct;
            return acct;
        } catch (DmlException e){
            System.debug('A DML exception has ocurred: '+ e.getMessage());
            return null;
        }
    }
}
Best Answer chosen by Vinicius Damasceno
Khan AnasKhan Anas (Salesforce Developers) 
Hi Vinicius,

Greetings to you!

I don't see anything visibly wrong with the above code. You might be getting this error because of the copy & paste issue. You can get characters that are not visible in the code, particularly when you copy/paste code.

Delete and re-type all the characters. Re-typing the code (not using copy/paste for anything) will fix the issue.

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks and Regards,
Khan Anas

All Answers

Khan AnasKhan Anas (Salesforce Developers) 
Hi Vinicius,

Greetings to you!

I don't see anything visibly wrong with the above code. You might be getting this error because of the copy & paste issue. You can get characters that are not visible in the code, particularly when you copy/paste code.

Delete and re-type all the characters. Re-typing the code (not using copy/paste for anything) will fix the issue.

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks and Regards,
Khan Anas
This was selected as the best answer
Ajay K DubediAjay K Dubedi
Hi Vinicius,

I have gone through your issue. I pasted the same code in my org and it worked fine. It may be a bug or something. Try creating a new class with a different name and paste this code. Remember to change the class name.


I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks and Regards,
Ajay Dubedi
www.ajaydubedi.com 
Kiran M 51Kiran M 51
Got same issue and resolved. This is because ; not added while executing / calling the method call - Anonumous window. ==> AccountHandler.insertNewAccount('XXX');