function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
rajesh k 10rajesh k 10 

how to get PricebookEntry listprice of each productids in salesforce using map?

Hi,
          map<Id,list<PricebookEntry>>  ProductidToPricebookEntry = new map<Id,list<PricebookEntry>>();
            set<ID> productids=new set<ID>();
            for(In_Product__c ip:InProductList)
            {
                productids.add(ip.Product__c);
               if(ProductidToPricebookEntry.containsKey(ip.Product__c))
                {
                    ProductidToPricebookEntry.get(ip.Product__c);
                }
            }
           
Bhanu MaheshBhanu Mahesh
Hi Rajesh,

Try below code to prepare the map
Map<Id,list<PricebookEntry>>  ProductidToPricebookEntry = new Map<Id,list<PricebookEntry>>();
for(PricebookEntry pricBkEntry : [SELECT Product2Id,Pricebook2Id,UnitPrice FROM PriceBookEntry]){
    if(ProductidToPricebookEntry.containsKey(pricBkEntry.Product2Id)){
    	ProductidToPricebookEntry.get(pricBkEntry.Product2Id).add(pricBkEntry);	    
     }
    else{
        List<PricebookEntry> lstPricbookEntry = new List<PricebookEntry>();
        lstPricbookEntry.add(pricBkEntry);
        ProductidToPricebookEntry.put(pricBkEntry.Product2Id,lstPricbookEntry);
    } 
}

Regards,
Bhanu Mahesh