I have a Custom object Product_Quantity__c and it has a lookup field for Product, when user going to select any of the Product from that lookup field in Visualforce page then what i need is that product's List Price will auto populate

However, i doing same thing for Product's ProductCode & description and it's working fine

i know ProductCode and Description are info of the Direct Product but List Price is info of the Product's PriceBookEntry

Can anyone tell me where i need to change in my code or what i have done wrong ?

Apex class :

mapPricebookEntryIdToPricebookEntry = new Map<Id, PricebookEntry>();
PriceBookEntry = new PricebookEntry();

public void retrieveproductInfo() {
    for(Product2 product : [SELECT Id, ProductCode, Description FROM Product2]) {
        mapProductIdToProduct.put(product.Id, product);
        mapPricebookEntryIdToPricebookEntry.put(product.Id, PriceBookEntry);
    if(PrdQuantity.Product__c != Null){
        this.partNumber = mapProductIdToProduct.get(PrdQuantity.Product__c).ProductCode;
        this.Description = mapProductIdToProduct.get(PrdQuantity.Product__c).Description;
        this.ListPrice = mapPricebookEntryIdToPricebookEntry.get(PrdQuantity.Product__c).UnitPrice;

Debug :

enter image description here

  • Can you output you got from debug statement. Does mapPricebookEntryIdToPricebookEntry have value?
    – Reshma
    Feb 1, 2017 at 9:26
  • @Reshma Please see updated Question, i have posted Debug log image as well Feb 1, 2017 at 9:30
  • PriceBookEntry has no value. Then how will you get value for unit price. Add a Pricebookentry to mapPricebookEntryIdToPricebookEntry
    – Reshma
    Feb 1, 2017 at 9:33
  • You mean there is no Pricebookentry available in that Product ? Feb 1, 2017 at 9:38
  • mapPricebookEntryIdToPricebookEntry.put(product.Id, PriceBookEntry); in this line how do you get value in 'PriceBookEntry'
    – Reshma
    Feb 1, 2017 at 10:02

1 Answer 1


You need to add a separate query to get PriceBookEntry.

for(PriceBookEntry entry : [SELECT Id, Product2Id, UnitPrice FROM PriceBookEntry]) { 
    mapPricebookEntryIdToPricebookEntry.put(entry.Product2Id, entry); 
  • I don't know why but it's appearing StandardPrice not UnitPrice, Standard Price = 100 $ & List Price = 102 $ Feb 1, 2017 at 10:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .