I am working on creating records for a custom object type in Salesforce. There is also a line item object which has a master-detail relationship.
- Invoice = Master
- Invoice Line Item = Detail
I am using JAVA to create these records after parsing an input XML file. The logic I am using to create invoice is as follows
- Parse XML file, create Invoice object for each Invoice node.
- Set the relevant fields.
- Store in SObject array.
After all invoices have been created, use one UPSERT call to create records.
UpsertResult[] upsertResults = connection.upsert("Invoice_ID__c", invoiceArray);
This is working fine. Now I need to create the invoice details. They are also in the XML file as child nodes of the Invoice node. I am a little confused about how to proceed. Since each Invoice detail line item will need to store the ID of its parent invoice which needs to be created first.
Is there a way of creating the master-detail records at the same time efficiently? If so where can I store the detail records at the time of calling the UPSERT call on the array storing all my Invoice records?
Thanks.