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

Filter a List of Products


  I have a list containing products and the pricebook values for the product.

For a given product, value doesn't exist in every pricebook. I need to filter the initial list so that I show only the products that have all the pricelists values to the user.

public List<ProductInfo> products {get; set;}

 products = new List<productInfo >();
  Map<Id, productInfo> pInfoMap = new Map<Id, productInfo>();
  for (PricebookEntry pEntry :[Select id, unitPrice, product2Id, product2.Name, product2.Description, product2.Family, pricebook2id, from PricebookEntry order by product2.Name LIMIT 300 ])  {
                ProductInfo pInfo = new ProductInfo();
                if(!pInfoMap.containsKey(pEntry.product2Id)) {
           = new Product2(id=pEntry.product2Id, Name=pEntry.product2.Name, Description=pEntry.product2.Description,);
                    pInfoMap.put(pEntry.product2Id, pInfo);                   
                } else {
                    pInfo = pInfoMap.get(pEntry.product2Id);

....Similarly I do for each price book name.

 products = pInfoMap.values();


I need to filter this products table so that I only show the products which have prices in all pricebooks.