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, AND PriceBook2Id IN : Pbook2Id This works in Apex for an ID Field, if it didn't you'd have to construct a List<Id> for comparison List<Id> PriceBookIds = new List<Id>(); for(PriceBook2 pb : Pbook2Id) //iterate over the list and collect ids for comparison PriceBookIds.add(pb.Id); 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()