You need to sign in to do that
Don't have an account?
Rory McDonnell
For loop error?
Hi I am somewhat of a novice when it comes to apex and can't seem to work out what the problem is with line 7 of my code. I am building a practice trigger that creates 10 identical opportunities whenever an account has more than 99 employees.
I think I have set up the for loop correctly but in the developer console 'Problem' there are a number of messages on line 7
- Expecting ';' but was a '<'
- Expecting ';' but was a ','
- Expecting ';' but was a ')'
Any suggestions?
I think I have set up the for loop correctly but in the developer console 'Problem' there are a number of messages on line 7
- Expecting ';' but was a '<'
- Expecting ';' but was a ','
- Expecting ';' but was a ')'
Any suggestions?
trigger CreateTenOpps on Account (before insert) { List<Opportunity> TenOpps = New List<Opportunity>(); for (Account acc : Trigger.new) { if (acc.NumberOfEmployees > 100) { for (Integer i = 0, i < 10, i++) { Opportunity opp = New Opportunity(CloseDate = date.today(), StageName = 'Prospecting', Name = 'Trigger Opp'); TenOpps.add(opp); } insert TenOpps; } } }
In Line no: 7 you have to use the Semi Colon " ; " don't use the comma in for loop.
trigger CreateTenOpps on Account (before insert) {
List<Opportunity> TenOpps = New List<Opportunity>();
for (Account acc : Trigger.new) {
if (acc.NumberOfEmployees > 100) {
for (Integer i = 0; i < 10; i++) { /// use the Semi colon here .
Opportunity opp = New Opportunity(CloseDate = date.today(),
StageName = 'Prospecting', Name = 'Trigger Opp');
TenOpps.add(opp);
}
insert TenOpps;
}
}
}
Thanks,
Maharajan.C
All Answers
In Line no: 7 you have to use the Semi Colon " ; " don't use the comma in for loop.
trigger CreateTenOpps on Account (before insert) {
List<Opportunity> TenOpps = New List<Opportunity>();
for (Account acc : Trigger.new) {
if (acc.NumberOfEmployees > 100) {
for (Integer i = 0; i < 10; i++) { /// use the Semi colon here .
Opportunity opp = New Opportunity(CloseDate = date.today(),
StageName = 'Prospecting', Name = 'Trigger Opp');
TenOpps.add(opp);
}
insert TenOpps;
}
}
}
Thanks,
Maharajan.C