+ Start a Discussion
AMIT KUMAR 73AMIT KUMAR 73 

SOQL Query to Retrieve Price Book Name for a associated product

Hi,

I am trying to retrieve Product Name, Product code & Pricebook Name associated with a PRODUCT.

--------------------------------------------------------------------------------------------------------------------------------------------------------
Product2 productdet = [Select Id, Name, ProductCode From Product2 where id='01tA00000033x2z'];
--------------------------------------------------------------------------------------------------------------------------------------------------------

How to modify this query to associate PriceBook details this  Product belongs to.

Product

Shashikant SharmaShashikant Sharma
I think you can not access it diresclty in one query but need to make another query

Map<Id, PricebookEntry> mapPricebookEntry = new Map<Id, PricebookEntry>( [ Select
                                                                                   Product2Id,
                                                                                   Product2.Name,
                                                                                   Product2.Restoration_Fee__c
                                                                                   From PricebookEntry
                                                                                   Where Product2Id =: productdet
                                                                                   ]
                                                                                 );

If there are multiple product price book entry need to be mapped then you have to create a map


Map<Id, PricebookEntry> mapProdctIdToPricebookEntry = new Map<Id, PricebookEntry>();


Jim CookJim Cook
Late to the party, but try this:
SELECT Name, Product2.Name, Product2.ProductCode, PriceBook2.Name from PriceBookEntry where Product2.Name = 'whatever'