Out of the box, Salesforce allows the ability to insert two different types of SObjects to be inserted in the same DML (Data Manipulation Language). However, this limitation forces us to insert parent-child relationship records for the same SObject type in multiple DMLs. The result of this is poor performance and hitting APEX limits that auto-rollback all changes done. 

In the new platform, we are rolling out the ability to insert level of parent-child relationships of the same SObject type in a single DML. Currently, we are supporting this for Sales Order Line objects. If our Order Service is used, this will automatically do this work for you. For example, if you have the following scenario:

  1. Parent Item
    1. Required Package Item
    2. Required Package Item
    3. Optional Package Item

In the past, this is three DML statements. One to insert the parent, one to insert the two required package items, and one to insert the optional package items. As you can see, this causes us to execute the Sales Order Line Trigger three times. As we move to the new platform, all of the above would happen in one single DML. We have introduced the following fields on the Sales Order Line:

  1. OrderApi__Foreign_Key__c
  2. OrderApi__Parent_Foreign_Key__c

If you insert records directly the following would need to happen for one DML to work:

  1. Parent Item (Foreign Key)
    1. Required Package Item (Parent Foreign Key would be the Foreign Key from the Parent)
    2. Required Package Item (Parent Foreign Key would be the Foreign Key from the Parent)
    3. Optional Package Item (Parent Foreign Key would be the Foreign Key from the Parent)

If more levels are needed the above would be repeated for each level.