I'm getting the following error:

Save error: Initial term of field expression must be a concrete SObject: LIST Force.com save problem

Here are the snippets of code in question:

List <PricebookEntry> newProdsList = [SELECT ID //Creating a new PricebookEntry list with all relevant information
                                        ProductCode in: productCodes
                                        Pricebook2Id in: Pbook2Id.Id

The error is ocurring on the line Pricebook2Id in: Pbook2Id.Id.

Here is what Pbook2Id looks like:

List<Pricebook2> Pbook2Id = [SELECT Name
                                FROM Pricebook2 
                                    WHERE Name='Support Renewal' AND IsActive=true];

My question is, what does this error mean? I've looked at other such errors here and I'm not sure I fully understand why it's being caused.


Pbook2Id is a collection, so it doesnt have a field called Id.

The dot notation to access a field can only be used on an sObject (you can access static / instance variables using Class / Object names too)

In summary,

PriceBook2Id IN : Pbook2Id

This works in Apex for an ID Field, if it didn't you'd have to construct a List for comparison

List<Id> PriceBookIds = new List<Id>();
for(PriceBook2 pb : Pbook2Id) //iterate over the list and collect ids for comparison

and then use

PriceBook2Id IN :PriceBookIds

You can also cast to a Map dynamically and use the keySet for comparison

Map<Id, Pricebook2> Pbook2Id = new Map<Id, PriceBook2>([SELECT Id, Name
                                FROM Pricebook2 
                                    WHERE Name='Support Renewal' AND IsActive=true]);

And then Use

PriceBook2Id IN :Pbook2Id.keySet()
  • but since Pbook2Id has two columns (Name and ID), shouldn't i need to specify which one of those columns I want it to match with? Or does apex know to look only at the ID column of the list? Your answer worked completely but I just don't understand the logic behind it. Thanks for your help! – SSadat Jul 4 '13 at 14:23
  • It understands when used with an Id, I don't believe you'd be able to do it with a different field, for e.g. name. If it didnt, you've have to iterate over PBook2Id and add the Ids to a List<Id> and then use an IN on the List<Id> – techtrekker Jul 4 '13 at 14:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.