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

Initial term of field expression must be a concrete SObject: List<Allocation__c>
Hi All
I have searched for multiple post to find an answer for this common error but I am not sure what mistake I am commiting.. All I need to do query a local list and add ID's to a SET so that I dont execute multiple SOQL's. Appreciate your help on this
My CODE
I am using "Execute Highlight" option to see if my code works and it breaks in line 7
I have searched for multiple post to find an answer for this common error but I am not sure what mistake I am commiting.. All I need to do query a local list and add ID's to a SET so that I dont execute multiple SOQL's. Appreciate your help on this
My CODE
I am using "Execute Highlight" option to see if my code works and it breaks in line 7
Line: 7, Column: 18
Initial term of field expression must be a concrete SObject: List<Allocation__c>
Initial term of field expression must be a concrete SObject: List<Allocation__c>
List <Allocation__C> lst = new List <Allocation__c>(); lst = [Select Percentage__c, Line_of_Business__c, Support_Contract__c from Allocation__C WHERE Percentage__c = 50 LIMIT 1 ]; Set<ID> supConID = new Set<ID>(); --IS THIS THE CORRECT DATA STRUCTURE for(Allocation__C al :lst) -- THIS IS WHERE THE ERROR HAPPENS, { supConID.Add(lst.Support_Contract__c); } List <Request__C> req = new List <Request__c>(); req = [Select ID, LOB_Allocations__c FROM Request__c WHERE ID IN (Select Support_Contract__c from Allocation__C WHERE Percentage__c = 50)]; List <Allocation__C> alloc = new <Allocation__c>(); List <Request__C> reqUpdate = new <Request__C>(); for(Request__C r: req) { string lobstring = ''; Request__c rtemp = new Request__c(); for(Allocation__c a: [select Line_of_Business__c, Percentage__c FROM lst WHERE Support_Contract__c = :r.ID]) { lobstring += (lobstring ==''?'':' / ')+a.Line_of_Business__c+'('+ a.Percentage__c + '%)'; } rtemp.ID = r.ID; rtemp.LOB_Allocations__c = lobstring; reqUpdate.Add(rtemp); } update reqUpdate; /*List<Request__C, string> fnl = new List<Request__c , string>; for ( Allocation__C ac :lst) { ac.Allocation_Notes__c = ac.Allocation_Notes__c; update ac; }*/
At Line 5, you are already iterating Allocation__C object. So instead of doing "supConID.Add(lst.Support_Contract__c);" what you should be doing is this "supConID.Add(al.Support_Contract__c);"... See line 7 of updated code below .. This will create a set of all your "Support_Contract__c" Ids in supConID
Please mark this as Best Answer if it helps you!
All Answers
At Line 5, you are already iterating Allocation__C object. So instead of doing "supConID.Add(lst.Support_Contract__c);" what you should be doing is this "supConID.Add(al.Support_Contract__c);"... See line 7 of updated code below .. This will create a set of all your "Support_Contract__c" Ids in supConID
Please mark this as Best Answer if it helps you!
Line 21
for(Allocation__c a: [select Line_of_Business__c, Percentage__c FROM lst WHERESupport_Contract__c = :r.ID])
The intention is to hit the database as few times as possible. What data structure should I use for me to query. In .NET LINQ we can do these, so I am assuming we can do something similar in here, may be I am not getting the correct syntax or not using the right data structure.
As long as you dont add SOQL query in 'For' loop, it should be fine.
Also, to reduce number of records you want to hit, you can try using Maps collection. See example below,
Hope this helps.