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
krishna reddy Singampallikrishna reddy Singampalli 

DML requires Sobject or Sobject list type:Account

public class MyAccount {
    public String name {set;get;}
    public String phone {set;get;}
    public String rating {set;get;}
    public void create(){
        Account acc=new Account();
        acc.name=name;
        acc.phone=phone;
        acc.rating=rating;
  10)       insert acc;
    }
    
}
Best Answer chosen by krishna reddy Singampalli
sakhisakhi
public class MyAccount {
    public String name {set;get;}
    public String phone {set;get;}
    public String rating {set;get;}
    public void getcreate(){
        Account acc=new Account();
        acc.name=name;
        acc.phone=phone;
        acc.rating=rating;
         insert acc;
    }
    
}

All Answers

AbhinavAbhinav (Salesforce Developers) 
Hi
can you tell why you have written this   10)  before inserting acc?

Thanks!
krishna reddy Singampallikrishna reddy Singampalli
Showing error line 10
AbhinavAbhinav (Salesforce Developers) 
how you are calling this class?
 
krishna reddy Singampallikrishna reddy Singampalli
To insert a record why we are calling
 
Suraj Tripathi 47Suraj Tripathi 47
Hi Krishna,
Please Use the get keyword before the method name
ex: Or Use this Code-

Controller -->
public class MyAccount {
    public String name {set;get;}
    public String phone {set;get;}
    public String rating {set;get;}
    public void getcreate(){
        Account acc=new Account();
        acc.name=name;
        acc.phone=phone;
        acc.rating=rating;
         insert acc;
    }
    
}



Visualforce Code -->
<apex:page controller="Controller_Account_Insert"><apex:form>
    <apex:pageBlock>
    <apex:pageBlockSection>
        Enter Account Name :<apex:inputText value="{!name}"/>
        Enter Contact Number: <apex:inputText value="{!phone}"/>
        Enter Rating :<apex:inputText value="{!rating}"/>
        
        <apex:commandButton value="Create" action="{!getCreate}"/>
        </apex:pageBlockSection>
    </apex:pageBlock>
    </apex:form>
</apex:page>



If you find your Solution then mark this as the best answer. 

Thank you!

Regards,
Suraj Tripathi
sakhisakhi
public class MyAccount {
    public String name {set;get;}
    public String phone {set;get;}
    public String rating {set;get;}
    public void getcreate(){
        Account acc=new Account();
        acc.name=name;
        acc.phone=phone;
        acc.rating=rating;
         insert acc;
    }
    
}
This was selected as the best answer
krishna reddy Singampallikrishna reddy Singampalli
Thanks, I'll check them out.
krishna reddy Singampallikrishna reddy Singampalli
Boss again it shows error while i am insert acc;
Suraj Tripathi 47Suraj Tripathi 47
Hi Krishna,
Please Share your error here.

Thank you!

Regards,
Suraj Tripathi
krishna reddy Singampallikrishna reddy Singampalli
Tnx i got it