You need to sign in to do that
Don't have an account?
Engine 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!
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;
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;
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.