Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
up vote 6 down vote accepted

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>'
share|improve this answer
Yes but pricebookentry doesnt support pagination. – Keepcalmncode Jan 3 '13 at 8:15
I suggest you repost this as a separate question. – Rob Woodward Jan 3 '13 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, FROM PricebookEntry WHERE Pricebook2Id = '01sG00000002L5mIAE'
share|improve this answer
Yes I have the pricebook with the above id.But its returning all the products. – Keepcalmncode Jan 2 '13 at 13:57

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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