0

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.

0

2 Answers 2

6

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>'
2
  • Yes but pricebookentry doesnt support pagination. Jan 3, 2013 at 8:15
  • I suggest you repost this as a separate question. Jan 3, 2013 at 10:15
0

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.

EDIT:

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'
1
  • Yes I have the pricebook with the above id.But its returning all the products. 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 .