+ Start a Discussion
Engine ForceEngine Force 

Insert account and contacts in one DML

Hi There,

 

Is it possible to insert account and contacts at the same time in one DML: insert(new account(name='acct1'), contact = new contact())?

 

Thanks!

ForcepowerForcepower

Not sure about that.

You could do something like this:

 

     List<SObject> sobj = new List<SObject>();
      
     sobj.add(new account(name='acct1'));
     sobj.add(new contact(LastName='Lname1'));
     insert sobj;

sfdcfoxsfdcfox
Mixed SObject cannot be passed as parameters to DML functions. You will need two DML operations to create/modify/delete accounts and contacts.
ForcepowerForcepower
sfdcfox,

Not sure if you were referring to my example above. This does work:
List<SObject> sobj = new List<SObject>();

sobj.add(new account(name='acct1'));
sobj.add(new contact(LastName='Lname1'));
insert sobj;
Bhawani SharmaBhawani Sharma
Hi Ram,

you are correct, but there is a limit of Object Type in dynamic sObject list. You can not have more than 10 type of Sobject is dynamic list. So I would prefer to keep each object as separate list.