Have one custom object Orders_OMS__c.
Account has two child relationship with it
account.Order_OMS__r
account.Order_OMS1__r
Question:
How to insert list of newly created Orders_OMS__c into
account.Order_OMS__r
or
account.Order_OMS1__r
Below is the code [It always inserts only to one relation account.Order_OMS1__r and not to the other] Note: There are records with orderType.isOMSOrder==true and orderType.isOMSOrder==false
insert newOmsOrders;
if (orderType.isOMSOrder) {
for (Orders_OMS__c omsOrder : newOmsOrders) {
System.debug('adding to account.Order_OMS__r omsOrder.Id ' + omsOrder.Id);
account.Order_OMS__r.add(omsOrder);
}
//account.Order_OMS__r.addall(newOmsOrders);
insert account.Order_OMS__r;
//upsert account.Order_OMS__r;
} else {
for (Orders_OMS__c omsOrder : newOmsOrders) {
System.debug('adding to account.Order_OMS1__r omsOrder.Id ' + omsOrder.Id);
account.Order_OMS1__r.add(omsOrder);
}
//account.Order_OMS1__r.addall(newOmsOrders);
insert account.Order_OMS1__r;
//upsert account.Order_OMS1__r;
}