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: Contact

public class DML {
    public Account acc {set;get;}
    public Contact con {set;get;}
    public DML(){
        acc=new Account();
        con=new Contact();
    }
    public void create (){
        insert acc;
        con.accountId=acc.Id;
        insert con;
    }
}
Suraj Tripathi 47Suraj Tripathi 47

Hi Krishna,

you can't insert Account or Contact without providing required fields.

Try this code:

public class DML {
    public Account acc {set;get;}
    public Contact con {set;get;}
    public DML(){
        acc=new Account();
        con=new Contact();
    }
    public void create (){
        acc.name='Danioel';
        insert acc;
        con.lastname='James';
        con.accountId=acc.Id;
        insert con;
    }
}
 

Please mark it as Best Answer ,if it helps.

Thanks