• Prerna Raj 7
  • NEWBIE
  • 0 Points
  • Member since 2021

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 1
    Replies
I am new to coding and am still learning. I am getting the error for  "variable does not exist : i " in my code below -   I have made the 2 lines in which i am getting the error bold

trigger LeadingCompetitor on Opportunity (before insert, before update) {
    
    for (Opportunity opp : Trigger.new){
        //Add all prices to our list in order of competitors
            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 competitors to our list in order 
            List<String> competitorName = New List<String>();
            competitorName.add(opp.Competitor_1__c);
            competitorName.add(opp.Competitor_2__c);
            competitorName.add(opp.Competitor_3__c);
        
        //Loop throughall competitors to find the position of the lowest price
            Decimal lowestPrice;
            Integer lowestPricePosition;
        
            for (Integer i = 0; i < competitorPrices.size(); i++); {
                Decimal currentPrice = competitorPrices.get(i);
                if(lowestPrice == Null || currentPrice < lowestPrice) {
                    lowestPrice = currentPrice;
                     lowestPricePosition = i;
            }
            }
        //Populate the leading competitor field with the competitor matching the lowest price position
                   opp.Leading_Competitor__c = competitorName.get(lowestPricePosition);
                
    
    }    
}