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);
system.debug('====MAP====='+mapPricebookEntryIdToPricebookEntry);
}
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 :
mapPricebookEntryIdToPricebookEntry
have value?PriceBookEntry
has no value. Then how will you get value for unit price. Add aPricebookentry
tomapPricebookEntryIdToPricebookEntry
mapPricebookEntryIdToPricebookEntry.put(product.Id, PriceBookEntry);
in this line how do you get value in 'PriceBookEntry'