+ Start a Discussion
symantecAPsymantecAP 

Help with Test Class

Hi All 

 

I have a controller and I am working to deploy it to the server and it says code coverage failed 

I am struggling with the test class. Here is the controller. 

public class PriceBookserna {
    
   public class productInfo {
    
        public Product2 prod{get; set;}
        public List<PriceBookEntry> pbes {get; set;}
                public List<PriceBookEntry> pbef {get; set;}
                                public List<PriceBookEntry> pbea {get; set;}

                                public List<PriceBookEntry> pbeb {get; set;}
                                  // public List<PriceBookEntry> pbec {get; set;}


        public productInfo() {
            pbes = new List<PriceBookEntry>();
                        pbef = new List<PriceBookEntry>();
           pbea = new List<PriceBookEntry>();
           pbeb = new List<PriceBookEntry>();
                     // pbec = new List<PriceBookEntry>();



        }
        
    }
    
    public List<ProductInfo> products {get; set;}
    
    public PriceBookserna() {
        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,product2.ATFE_Status__c, product2.ProductCode, pricebook2id, pricebook2.name from PricebookEntry where   product2.ATFE_Product_Region__c='NA' and product2.Family= 'Service' and pricebook2.IsActive=true and Pricebook2.name='NA LA (USD)'      LIMIT 1000  ]) {
            ProductInfo pInfo = new ProductInfo();
            if(!pInfoMap.containsKey(pEntry.product2Id)) {
                pInfo.prod = new Product2(id=pEntry.product2Id, Name=pEntry.product2.Name, Description=pEntry.product2.Description, Family=pEntry.product2.Family,ATFE_Status__c=pEntry.product2.ATFE_Status__c, ProductCode=pEntry.product2.ProductCode);
                pInfo.pbes.add(pEntry);

                pInfoMap.put(pEntry.product2Id, pInfo);
            } else {
                pInfo = pInfoMap.get(pEntry.product2Id);
                pInfo.pbes.add(pEntry);
            }
        }
        
        for (PricebookEntry pEntry1 :[Select id, unitPrice, product2Id, product2.Name, product2.Description, product2.Family,product2.ATFE_Status__c, product2.ProductCode, pricebook2id, pricebook2.name from PricebookEntry where   product2.ATFE_Product_Region__c='NA' and product2.Family= 'Service' and pricebook2.IsActive=true and Pricebook2.name='NA DIST (USD)'  LIMIT 1000  ]) {
            ProductInfo pInfo = new ProductInfo();
            if(!pInfoMap.containsKey(pEntry1.product2Id)) {
                pInfo.prod = new Product2(id=pEntry1.product2Id, Name=pEntry1.product2.Name, Description=pEntry1.product2.Description, Family=pEntry1.product2.Family,ATFE_Status__c=pEntry1.product2.ATFE_Status__c, ProductCode=pEntry1.product2.ProductCode);
                pInfo.pbef.add(pEntry1);

                pInfoMap.put(pEntry1.product2Id, pInfo);
            } else {
                pInfo = pInfoMap.get(pEntry1.product2Id);
                pInfo.pbef.add(pEntry1);
            }
        }
        
         for (PricebookEntry pEntry2 :[Select id, unitPrice, product2Id, product2.Name, product2.Description, product2.Family,product2.ATFE_Status__c, product2.ProductCode, pricebook2id, pricebook2.name from PricebookEntry where   product2.ATFE_Product_Region__c='NA' and product2.Family= 'Service' and pricebook2.IsActive=true and Pricebook2.name='NA AP (USD)'      LIMIT 1000  ]) {
            ProductInfo pInfo = new ProductInfo();
            if(!pInfoMap.containsKey(pEntry2.product2Id)) {
                pInfo.prod = new Product2(id=pEntry2.product2Id, Name=pEntry2.product2.Name, Description=pEntry2.product2.Description, Family=pEntry2.product2.Family,ATFE_Status__c=pEntry2.product2.ATFE_Status__c, ProductCode=pEntry2.product2.ProductCode);
                pInfo.pbea.add(pEntry2);

                pInfoMap.put(pEntry2.product2Id, pInfo);
            } else {
                pInfo = pInfoMap.get(pEntry2.product2Id);
                pInfo.pbea.add(pEntry2);
            }
        }
       
      for (PricebookEntry pEntry3 :[Select id, unitPrice, product2Id, product2.Name, product2.Description, product2.Family,product2.ATFE_Status__c, product2.ProductCode, pricebook2id, pricebook2.name from PricebookEntry where   product2.ATFE_Product_Region__c='NA' and product2.Family= 'Service' and pricebook2.IsActive=true and Pricebook2.name='NA LA (USD)'      LIMIT 1000  ]) {
            ProductInfo pInfo = new ProductInfo();
            if(!pInfoMap.containsKey(pEntry3.product2Id)) {
                pInfo.prod = new Product2(id=pEntry3.product2Id, Name=pEntry3.product2.Name, Description=pEntry3.product2.Description, Family=pEntry3.product2.Family,ATFE_Status__c=pEntry3.product2.ATFE_Status__c, ProductCode=pEntry3.product2.ProductCode);
                pInfo.pbeb.add(pEntry3);

                pInfoMap.put(pEntry3.product2Id, pInfo);
            } else {
                pInfo = pInfoMap.get(pEntry3.product2Id);
                pInfo.pbeb.add(pEntry3);
            }
        }
   /* for (PricebookEntry pEntry4 :[Select id, unitPrice, product2Id, product2.Name, product2.Description, product2.Family,product2.ATFE_Status__c, product2.ProductCode, pricebook2id, pricebook2.name from PricebookEntry where   product2.ATFE_Product_Region__c='NA' and product2.Family= 'PRODUCT' and pricebook2.IsActive=true and Pricebook2.name like'%(USD)'      LIMIT 1000  ]) {
            ProductInfo pInfo = new ProductInfo();
            if(!pInfoMap.containsKey(pEntry4.product2Id)) {
                pInfo.prod = new Product2(id=pEntry4.product2Id, Name=pEntry4.product2.Name, Description=pEntry4.product2.Description, Family=pEntry4.product2.Family,ATFE_Status__c=pEntry4.product2.ATFE_Status__c, ProductCode=pEntry4.product2.ProductCode);
                pInfo.pbec.add(pEntry4);

                pInfoMap.put(pEntry4.product2Id, pInfo);
            } else {
                pInfo = pInfoMap.get(pEntry4.product2Id);
                pInfo.pbec.add(pEntry4);
            }
        }*/
       
    
        
        products = pInfoMap.values();
    }
     
    
}

 

Please help me with the Test Class. 

 

symantecAPsymantecAP

Here is the test method I have written so far. But it doesnt cover any code. 

@isTest

private class testpricebook{

private static testmethod void testpb(){

PriceBookEntry pbe1=[Select id,unitprice,Product2Id,Product2.Name,
                        Product2.Description,Product2.Family from PriceBookEntry 
                         where product2.ATFE_Product_Region__c='NA' and product2.Family='PRODUCT'  limit 1]; 
Product2 prod = new Product2(Name='AT-iMG008GNB-10',Description='Grounded UPS without battery. Battery must be ordered separetly');



}



}