You need to sign in to do that
Don't have an account?

Initial term of field expression must be a concrete SObject: List<Opportunity>
Hello, I'm creating a test class for a visualforce controller but I'm getting the "Initial term of field expression must be a concrete SObject: List<Opportunity>" error.
I have a formula field on the opportunity object : Number_of_Employess_Summary__c
Here is my code
Help needed please.
Thank you.
I have a formula field on the opportunity object : Number_of_Employess_Summary__c
Here is my code
@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(); } }
Help needed please.
Thank you.
It should be
for(Opportunity testOppAfterInsert: opps)
and not
for(testOppAfterInsert: opps)
Also if the only thing you want is to query some addition value you can replace line 33 to 36 with
All Answers
On Line number 33 in for loop you have Please replace it with The syntax of foreach loop expect the intial variable to be of concrete type and not a collection.
On a side note it looks like you are executing query inside for loop. This is a big No, Please follow the Apex best practices and ensure that your code is bulkified.
Hope this helps.
Thank you.
It should be
for(Opportunity testOppAfterInsert: opps)
and not
for(testOppAfterInsert: opps)
Also if the only thing you want is to query some addition value you can replace line 33 to 36 with
Initial term of field expression must be a concrete SObject: List<Opportunity>" error
And looks like you did not used my exact code. Please note the difference in where clause. I have mentioned opps and you are using opps.Id
You are the best.
Thanks.