+ Start a Discussion
Kathir DevanKathir Devan 

Compile Error: DML requires SObject or SObject list type: LIST<MyForce.Account> at line 29 column 9

     here i hav attached my vf and controller code,i hav found the following error... DML requires SObject or SObject list type.....kindly anyone of u help me friends

vf code:
<apex:page StandardController="Account" extensions="MultiAdd" id="thePage">
<apex:form >
<apex:pageblock id="pb" >
    <apex:pageBlockButtons >
        <apex:commandbutton value="Add" action="{!Add}" rerender="pb1"/>
        <apex:commandbutton value="Save" action="{!Save}"/>
        <apex:pageblock id="pb1">
        <apex:repeat value="{!lstInner}" var="e1" id="therepeat">
                <apex:panelGrid columns="5">
                <apex:panelGrid headerClass="Name">
                    <apex:facet name="header">Del</apex:facet>
                    <apex:commandButton value="X" action="{!Del}" rerender="pb1">
                        <apex:param name="rowToBeDeleted" value="{!e1.recCount}" assignTo="{!selectedRowIndex}"></apex:param>
                <apex:panelGrid title="SPD" >
                    <apex:facet name="header">Country</apex:facet>
                    <apex:inputfield value="{!e1.acct.ShippingCountry}"/>
                <apex:panelGrid >
                    <apex:facet name="header">IsActive</apex:facet>
                    <apex:inputfield value="{!e1.acct.Active__c}"/>
                <apex:panelGrid >
                    <apex:facet name="header">Name</apex:facet>
                    <apex:inputfield value="{!e1.acct.Name}"/>


public class MultiAdd
    //will hold the account records to be saved
    public List<Account>lstAcct  = new List<Account>();
    //list of the inner class
    public List<innerClass> lstInner
    {   get;set;    }
    //will indicate the row to be deleted
    public String selectedRowIndex
    //no. of rows added/records in the inner class list
    public Integer count = 1;
    ////save the records by adding the elements in the inner class list to lstAcct,return to the same page
    public PageReference Save()
        PageReference pr = new PageReference('/apex/customlookup');
        for(Integer j = 0;j<lstInner.size();j++)
        insert lstAcct;
        return pr;
    //add one more row
    public void Add()
        count = count+1;
    /*Begin addMore*/
    public void addMore()
        //call to the iner class constructor
        innerClass objInnerClass = new innerClass(count);
        //add the record to the inner class list
    }/* end addMore*/
    /* begin delete */
    public void Del()
        system.debug('selected row index---->'+selectedRowIndex);
        count = count - 1;
    }/*End del*/
    public MultiAdd(ApexPages.StandardController ctlr)
        lstInner = new List<innerClass>();
        selectedRowIndex = '0';
    }/*End Constructor*/

    /*Inner Class*/
    public class innerClass
        /*recCount acts as a index for a row. This will be helpful to identify the row to be deleted */
        public String recCount
        public Account acct
        /*Inner Class Constructor*/
        public innerClass(Integer intCount)
            recCount = String.valueOf(intCount);       
            /*create a new account*/
            acct = new Account();
        }/*End Inner class Constructor*/   
    }/*End inner Class*/
}/*End Class*/

                                                                                                    thanks in advance!!!!!!!!!!!!!
I'm assuming it's this line that's causing the problem -- "insert lstAcct;" (It's at 29 on the controller).  
However, this line looks OK to me.
And then, when I create a new class in a new dev org, it compiles just fine in the dev console.
So what am I missing?  Where are you seeing this error?
Did you define a class, whose name is 'Account' ?

For exmaple, I can define 'Account' class like this.
public class Account {
  public String name {get; set;}

but, this code raise compile error.
because 'Account' in this code means NOT Custom Object BUT user define class.
List<Account> lstAcc = new List<Account>();
insert lstAcc     // <- Compile Error raised: DML requires SObject or SObject list type: LIST<Account>

please check your code if you defined 'Account' class.