以编程方式保存SaleOrder

When I save a Product object I would like to perform/trigger a save() on a specific sales order via a workflow function.

I tried to use the standard save function but all my products are deleted in the sales order:

$moduleName = 'SalesOrder';
$recordId = $salesOrderId;
$recordModel= Vtiger_Record_Model::getInstanceById($recordId,$moduleName);
$recordModel->set('mode', 'edit');
$recordModel->save();

Is there a way to programmatically perform a save on SalesOrder object?

You have apply insert queries manually after you save event triggered and to do that first you have to get the previous Product Line Item data in array then after save event of SalesOrder apply insert query for array one by one. That same thing vtiger do.