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.

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>'
  • 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
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'
  • 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 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.