I get errors for the last line.
Method does not exist - {List}.get(Decimal)
opp.Most_Expensive_Competitor_Price__c = oppCompetitorPrices.get(highestPrice);
I am trying to populate the Most_Expensive_Competitor_Price__c with the Highest Price
trigger MostExpensiveCompetitor on Opportunity (before insert, before update) {
for (Opportunity opp: Trigger.new) {
// create a list to add the competitor prices
List <Decimal> oppCompetitorPrices = new List <Decimal> ();
oppCompetitorPrices.add(opp.Competitor_1_Price__c);
oppCompetitorPrices.add(opp.Competitor_2_Price__c);
oppCompetitorPrices.add(opp.Competitor_3_Price__c);
// create a list to add the competitors in the same order
List <String> competitors = new List <String> ();
competitors.add(opp.Competitor_1__c);
competitors.add(opp.Competitor_2__c);
competitors.add(opp.Competitor_3__c);
Decimal highestPrice;
Integer highestPricePosition;
for (Integer i=0; i<oppCompetitorPrices.size(); i++) {
Decimal currentHighestPrice = oppCompetitorPrices.get(i);
if (highestPrice ==null || currentHighestPrice > highestPrice) {
highestPrice = currentHighestPrice;
highestPricePosition = i;
}
}
opp.The_Most_Expensive_Competitor__c = competitors.get(highestPricePosition);
opp.Most_Expensive_Competitor_Price__c = oppCompetitorPrices.get(highestPrice);
}
}