Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

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
1  
Try getting a better accept rate if you want answers. –  Martin Peters Jan 2 '13 at 13:41
add comment

2 Answers

up vote 5 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. –  Kapil Jan 3 '13 at 8:15
    
I suggest you repost this as a separate question. –  Rob Woodward Jan 3 '13 at 10:15
add comment

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'
share|improve this answer
    
Yes I have the pricebook with the above id.But its returning all the products. –  Kapil Jan 2 '13 at 13:57
add comment

Your Answer

 
discard

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.