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
ram123ram123 

Creating Parent Child Record in one dml ?

1.

 

i have parent child relationship between contract line item (its custom object not the sfdc standard object), i like to know how to create both parent and child in one dml statement and let salesforce do the work of maping relationship.

 

example of what I'm expecting, where parentId refers parent contractlineitem record

 

ContractLineItem parent = new ContractLineItem();

ContractLineItem child = new ContractLineItem();

child.parentId = parent;

isnert new List<ContractLineItem>{parent, child};

 

 

2. also jsut curious, if the same case is possible for cross objects, i mean account/cases. assuming account is parent of cases ?

 

 

Thanks

Ram

 

 

 

Starz26Starz26

You cannot do this.

 

You have to create the parent then the child. mapping the relationship yourself

bob_buzzardbob_buzzard

You can do this, but you need to use external id fields.  I wrote up a blog post on this last weekend:

 

http://bobbuzzard.blogspot.co.uk/2012/03/create-parent-and-child-records-in-one.html

ram123ram123

seems like resonable, still the only problem is you need the external Id to be "Unique" . The externalId can be unique if its coming from thrid party source or through integeration, but  if we have to generate one, its going to be tricky.

 

Thanks to both of you.

 

Ram