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
dedkinsdedkins 

Update related records in controller

 

I have a custom object (order__c), it has (product_item__c) items; the product items have a look up field for products in (product__c).  I'm trying to close the order and update the quantity of the product__c items through the product_item__c line item in the order.  But they are not updating.  The order closes and the fields update, but the items (and  do not update.

 

heirarchy

*order__c -> product_Item__c -> product__c

 

I'm trying to update two fields in product__c (ros__c and committed__c) by the qty field in product_item__c.  There may be multiple product items for an order, so it needs to iterate through the list.

 

Here's what I have - but it doesn't work:

 

public PageReference save(){

Order__c ord = [select id from Order__c where id = :Apexpages.currentPage().getparameters().get('id')];
List<Product_Item__c> products = new List<Product_Item__c>();

for (Product_Item__c p : [select id,inventory__r.committed__c,inventory__r.ros__c,qty__c from Product_Item__c where order__r.id = :ord.Id]){

p.inventory__r.committed__c = p.inventory__r.committed__c - p.qty__c;
p.inventory__r.ros__c = p.inventory__r.ros__c - p.qty__c;

products.add(p);
}

update products;

controller.save();

return null;

 

 

Thank you.