I have 3 custom objects, Object1, Object2, Object3. Object2 is the child of Object1. Object3 is the child of Object2.
So I want to insert multiple records into Object1, Object2, Object3.???
I have 3 custom objects, Object1, Object2, Object3. Object2 is the child of Object1. Object3 is the child of Object2.
So I want to insert multiple records into Object1, Object2, Object3.???
那么,你真的尝试过什么吗?
最简单的操作(不使用诸如外部 id 等高级技巧upsert
)是以正确的顺序进行。成功插入后,记录的 ID 将返回给对象,您可以在查找中使用它来建立关系。
Account a = new Account(Name = 'test acc');
insert a;
Contact c = new Contact(LastName = 'Test', AccountId = a.Id);
insert c;
AccountContactRole acr = new AccountContactRole(Role = 'President', AccountId = a.Id, ContactId = c.Id);
insert acr;
另一种方法是按照您想要的任何顺序执行此操作,然后使用适当的引用更新子记录...