You need to sign in to do that
Don't have an account?
Help fix code_
Still can't get the code below to work , for some reason I don't have the reply button, only the Answer button and when I use that to respond it's marking my own responses as best answer even the question is not solved yet.
trigger LeastCompetitorPrice on Opportunity (before insert, before update) { Integer highestPricePosition; Decimal highestPrices; Decimal lowestPrice; for(Opportunity opp : Trigger.new){ //Add all our prices in a list in order of competitor List<Decimal> competitorPrices = new List<Decimal>(); competitorPrices.add(opp.Competitor_1_Price__c); competitorPrices.add(opp.Competitor_2_Price__c); competitorPrices.add(opp.Competitor_3_Price__c); //Add all our competitors in a list in 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); //Loop through all competitors to find the position of the highest price for(integer i = 0; i<competitorPrices.size();i++){ Decimal currentPrice = competitorPrices.get(i); if(highestPrices == null || currentPrice > highestPrices){ opp.HighestPrice__c = highestPrices; system.debug(highestPrices); opp.HighestPrice__c = competitorPrices.get(highestPrices); if(lowestPrice == null || currentPrice > highestPrices) highestPricePositions = i; } } //Populate the leading highestPrice field with the highest price // matching the highest price position // opp.Leading_Competitor__c = competitors.get(highestPricePosition); }}

Try replacing the price comparison loop with following:
Hi Miika,
Thank you for looking into this for me, I have tried and did replace with your suggestion but still not working.
I have no idea why
Vida