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
sai manojsai manoj 

Apex Basics & Database Manipulate Records with DML

SandhyaSandhya (Salesforce Developers) 
Hi,

Below is the code which worked for me.
 
public class AccountHandler {

    public static Account insertNewAccount(String AccountName){

        Account acct = new Account(Name=AccountName);

        try {
            insert acct;

        } catch (DMLException e){
            return null;
        }

        return acct;
    }
}

Please mark it as solved if my reply was helpful. It will make it available for other as the proper solution.
                                             
Best Regards
Sandhya
 
Sandeep NallanaSandeep Nallana
public class AccountHandler {
    public static Account insertNewAccount(String AccountName){
        Account acct = new Account(Name=AccountName);
        try {
            insert acct;
        } catch (DMLException e){
            return null;
        }
        return acct;
    }
}