Here is my code
Help needed please.Thank you.@isTest
public class MyController {
static testMethod void ringMyBell(){
Integer numAccts;
Integer numOppsPerAcct;
List<Account> accts = new List<Account>();
for(Integer i=0;i<numAccts;i++) {
Account a = new Account(Name='TestAccount' + i,
RecordTypeId = '012800000003UY8',
Type = 'Prospect',
Number_Of_Employees__c = 190 + i
);
accts.add(a);
}
insert accts;
List<Opportunity> opps = new List<Opportunity>();
for (Integer j=0;j<numAccts;j++) {
Account acct = accts[j];
// For each account just inserted, add opportunities
for (Integer k=0;k<numOppsPerAcct;k++) {
opps.add(new Opportunity(Name=acct.Name + ' Opportunity ' + k,
CloseDate=System.today().addMonths(1),
StageName = 'Closed Won',
Number_Of_Employees_From_Opp = 200 + k,
AccountId=acct.Id));
}
}
// Insert all opportunities for all accounts.
insert opps;
//Populate the formula field Eligible Employees Summary
for(List<Opportunity> testOppAfterInsert: opps){
testOppAfterInsert = [select Name, Owner.Name, Number_Of__Employees_Summary__c, Number_Of_Employees_From_Opp, Account.Number_Of__Employees__c, StageName from Opportunity
WHERE Id IN :opps.Id];
}
MyController xyz = new MyController();
}
}
One error i see is that on line 33 you didnt replaced as i mentioned.It should befor(Opportunity testOppAfterInsert: opps)and notfor(testOppAfterInsert: opps) Also if the only thing you want is to query some addition value you can replace line 33 to 36 with
//Populate the formula field Eligible Employees Summary
List<Opportunity> testOppAfterInsert = new List<Opportunity>();
testOppAfterInsert = [select Name, Owner.Name, Number_Of__Employees_Summary__c, Number_Of_Employees_From_Opp, Account.Number_Of__Employees__c, StageName from Opportunity
WHERE Id IN :opps];