You need to sign in to do that
Don't have an account?
Apex Academy 2: Opportunity Price Wars
I've been doing David Liu's excellent Apex Academy courses to try and get introduced to Apex coding. But he uses MavensMate as his editor, which has now been dropped.
Using the built in Salesforce Developer Console, I get tonnes of errors. I've gone through and doubled checked all my code and I am pretty confident it is correct.
So what is causing all of these errors???

and here is my code:
trigger LeadingCompetitor on Opportunity (before insert, before update) {
for (Opportunity opp : Trigger.new) {
// all of 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 of our competitors in a list in the same order
List<String> competitors = List<String>();
competitors.add(opp Competitor_1__c);
competitors.add(opp Competitor_2__c);
competitors.add(opp Competitor_3__c);
// loop through all the competitors to find the position of the lowest price
Decimal lowestPrice;
Integer lowestPricePosition;
for (Interger 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 = competitors.get(lowestPricePosition);
}
}
Using the built in Salesforce Developer Console, I get tonnes of errors. I've gone through and doubled checked all my code and I am pretty confident it is correct.
So what is causing all of these errors???
and here is my code:
trigger LeadingCompetitor on Opportunity (before insert, before update) {
for (Opportunity opp : Trigger.new) {
// all of 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 of our competitors in a list in the same order
List<String> competitors = List<String>();
competitors.add(opp Competitor_1__c);
competitors.add(opp Competitor_2__c);
competitors.add(opp Competitor_3__c);
// loop through all the competitors to find the position of the lowest price
Decimal lowestPrice;
Integer lowestPricePosition;
for (Interger 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 = competitors.get(lowestPricePosition);
}
}
competitors.add(opp. Competitor_1__c);
competitors.add(opp .Competitor_2__c);
competitors.add(opp. Competitor_3__c);
Line 11 is missing new before list. It should be new list
Line 12 is missing a dot after opp. it should be
All Answers
competitors.add(opp. Competitor_1__c);
competitors.add(opp .Competitor_2__c);
competitors.add(opp. Competitor_3__c);
Line 11 is missing new before list. It should be new list
Line 12 is missing a dot after opp. it should be