0
public void caclculate_best_price(List<Goal_Items__c> goal_items){
    Map<Id, Map<Id, Map<Decimal, Decimal>>> Savings_Goals_to_Products_to_Sizes_to_Prices = build_savings_goal_to_product_price_map();
    for(Goal_Items__c goal_item: goal_items) {
        Map<Id, Map<Decimal, Decimal>> products_to_sizes_to_prices = Savings_Goals_to_Products_to_Sizes_to_Prices.get(goal_item.Goal_Items__c);
        Map<Decimal, Decimal> sizes_to_prices = null;
        if (products_to_sizes_to_prices != null) {
            sizes_to_prices = products_to_sizes_to_prices.get(goal_item.Product__c);
        }
        System.debug('goal_item:'  + goal_item);
        if(sizes_to_prices != null){
            Map<Decimal, Decimal> cache = new Map<Decimal, Decimal>();
            Set<Decimal> product_sizes_set = sizes_to_prices.keyset();
            List<Decimal> product_sizes_list = new List<Decimal>(product_sizes_set);
            product_sizes_list.sort();
            goal_item.Goal_Item_Price__c = find_best_price_and_validate_goal_item_amount(goal_item, goal_item.Desired_Units__c, cache, sizes_to_prices, product_sizes_list);
        } else {
            if (goal_item.Product__c != null) {
                goal_item.Product__c.addError('No product prices in the related Goal Item ('+ goal_item.Goal_Items__c +') Price Book for the related Product ('+ goal_item.Product__c+').');
            }
        }
    }
}

I seem to get the below error

Method does not exist or incorrect signature: void get(Decimal)" on line number 4. Could anyone know I might be doing wrong and possible hints to resolve this

1
  • pro tip -- follow conventions and don't name your methods or variables with underscores. e.g. sizesToPrices, not sizes_to_prices -- avoids confusing the developer when differentiating custom field names from apex variable and methodnames.
    – cropredy
    Mar 6, 2021 at 1:55

1 Answer 1

0

The first key in Savings_Goals_to_Products_to_Sizes_to_Prices is expected to be of type Id but based on the error message the field goal_item.Goal_Items__c is a Decimal.

There is probably a field on Goal_Items__c that is a lookup to "Savings Goals" that you should be using instead. Take a look at your data model.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .