Can anybody help me with this script, this is a simple update when the trigger is fired, (it works in sandbox) What can I use instead of items.values().PO_Details_Ordered__c = ... I am pretty sure this approach is causing this error. I will appreciate any help!
I tried this:
items.get(result.get('p')).PO_Details_Ordered__c = Double.valueof(result.get('ordered'));
I got this error:
Error: Compile Error: Incompatible key type Object for MAP at line 13 column 8
Trigger on the object:
trigger PODetailsCountsONProducts on NRProducts__c(before update) {
PODetailsCountsONProducts PODetailsCountsONProducts = new PODetailsCountsONProducts();
if (Trigger.isUpdate) {
PODetailsCountsONProducts.Run(Trigger.newMap);
}
}
Class:
System debug for items: USER_DEBUG [6]|DEBUG|{a0Cf0000002WxGMEA0=NRProducts__c:{all the fields for the NRProduct record......}}
public with sharing class PODetailsCountsONProducts {
public void Run(Map <Id, NRProducts__c> items) {
for (AggregateResult result: [SELECT NRProducts__c p
, SUM(Qty_Ordered__c) ordered
, SUM(Qty_Received__c) received
, MIN(Unit_Price__c) unitPrice
FROM Purchase_Order_Details__c
WHERE PO_Status__c = 'Placed'
AND Purchase_Order__r.Financial_Ownership_Date__c != NULL
AND NRProducts__c IN :items.keyset()
GROUP BY NRProducts__c
]) {
// here is the problem
items.values().PO_Details_Ordered__c = Double.valueof(result.get('ordered'));
items.values().PO_Details_Received__c = Double.valueof(result.get('received'));
items.values().Min_Price__c = Double.valueof(result.get('unitPrice'));
}
}
}