I want to update 2 fields on a Product record when a field is populated. The values I want to pull in are from another object so I believe the correct way is to get a filtered list of records from the new map. Do a query on the custom object and return records that match.
When I try to save the class I am working in I get an error:
Initial term of field expression must be a concrete SObject: List (Line: 15, Column: 29)
I know my initial list is for Product2 then I want to compare records in the Accounting_Unit__c object to the product2 records. Is there a right way to do this?
private void updatePA(Map<Id, Product2> newMap, Map<Id, Product2> oldMap)
{
List<Product2> prodsToUpdate = new List<Product2>();
for(Product2 prod : newMap.values())
{
if(prod.Product_LOB__c != null)
prodsToUpdate.add(prod);
}
List<Accounting_Unit__c> aUnits = [SELECT Id,
Name,
Practice_Area__c,
Sector__c
FROM Accounting_Unit__c
WHERE Name = :prodsToUpdate.Product_LOB__c
LIMIT 1];
for(Product2 prodUpdate : prodsToUpdate())
{
prodsToUpdate.Product_BU__c = aUnits.Practice_Area__c;
prodsToUpdate.Product_Sector__c = aUnits.Sector__c;
}
}