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
SV MSV M 

DML requires SObject or SObject list type: AccountClass

Here is my apex class
public class AccountClass
{
    public void createAccount(String Name)
    {
        AccountClass acc = new AccountClass();
        acc.Name = 'Test';
        insert acc;
    }
}

I am getting the following error while compiling,
DML requires SObject or SObject list type: AccountClass.

Can anyone help me how to resolve this error also tell me how to execute this class using Developer Console
Devi ChandrikaDevi Chandrika (Salesforce Developers) 
Hi sai,
You are giving accountclass instead of account.When creating an object record you have create a varibale to type Sobject.Here in your case Account
Try this code.
public class AccountClass
{
    public void createAccount(String Name)
    {
        Account acc = new Account();
        acc.Name = 'Test';
        insert acc;
    }
}

To execute
accountClass a = new accountClass();
a.createAccount('testAccount');

Hope this helps you
Let me know if this helps you. Kindly mark it as solved so that it may help others in future.

Thanks and Regards
SV MSV M
User-added image
Even after changing the class name I am still getting the errors. Can you help me resolve those errors.
Thank You.
Devi ChandrikaDevi Chandrika (Salesforce Developers) 
No need to change class name.You have to change the type of variable which you are creating inside createAccount method.
public class AccountClass
{
    public void createAccount(String Name)
    {
        Account acc = new Account();
        acc.Name = 'Test';
        insert acc;
    }
}

Hope this helps you
Let me know if this helps you. Kindly mark it as solved so that it may help others in future.

Thanks and Regards