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 Krishna ReddySv Krishna Reddy 

issue with insert con

public class Test_Contact {
    public Account acc {set;get;}
    public Contact con {set;get;}
    public Test_Contact(){
        acc=new Account();
        con=new Contact();
    }
    public void create(){
        insert acc;
        con.AccountId=acc.id;
        insert con;
        
    }
}
SwethaSwetha (Salesforce Developers) 
HI Krishna,
Please elaborate on the challenge/error you are facing
ShivankurShivankur (Salesforce Developers) 
Hi Krishna,

Please ensure whether you have an account inserted in the database before you pass an ID to the contact record while creating one,

Find an example over below link for similar functionality:
https://salesforce.stackexchange.com/questions/148974/inserting-accounts-and-contacts-simultaneously

Hope above information helps. Please mark as Best Answer so that it can help others in future.

Thanks.
Sv Krishna ReddySv Krishna Reddy
 it shows like
DML requires SObject or SObject list type: Contact
Sv Krishna ReddySv Krishna Reddy
  • The same code  i was executed in other org it's fine, but in my org shows error while insert Contact object Only