I am querying the products from a particular price book as below.

Select p.Name, p.Id, (Select Pricebook2Id, Product2Id From PricebookEntries where Pricebook2Id = '01sd0000000Pd8n') From Product2 p.

But above query is not evaluating the where condition.

I want to use this in pagination to show only related products based on pricebook.

Thanks in advance.


2 Answers 2


Your main query (ignoring the nested select) is essentially "Select Name, Id From Product2" so you get all products (subject to query limitations). Adding in the nested select says "for every row returned, also get the related PricebookEntries (but only from the given Pricebook)". So you still get all products + some extra related info if there's an entry in that Pricebook.

Everything you need is in PricebookEntry:

 Select Id, Name, ProductCode, Product2Id, UnitPrice
 From PricebookEntry where Pricebook2Id = '<insert id>'
  • Yes but pricebookentry doesnt support pagination. Commented Jan 3, 2013 at 8:15
  • I suggest you repost this as a separate question. Commented Jan 3, 2013 at 10:15

Your SOQL query is correct, but you are hard coding the Pricebook2Id = '01sd0000000Pd8n' in your WHERE condition. Confirm that you actually have a Pricebook with that id in your org.


If you want to return product information from a particular price book, try rephrasing your SOQL to

SELECT Product2Id,Product2.name FROM PricebookEntry WHERE Pricebook2Id = '01sG00000002L5mIAE'
  • Yes I have the pricebook with the above id.But its returning all the products. Commented Jan 2, 2013 at 13:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .