+ 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, pricebook2.name from PricebookEntry order by product2.Name LIMIT 300 ])  {
                ProductInfo pInfo = new ProductInfo();
                if(!pInfoMap.containsKey(pEntry.product2Id)) {
                    pInfo.prod = 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.