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
Prakhyat sapraPrakhyat sapra 

Can anyone help me to write the test class of this apex class???

public static List<ProductWrapper> getFilterProduct(String familyname,String searchtext){
        String filter ='SELECT Product2.Id,Name,Product2.Image_ID__c,Product2.Family,UnitPrice '
                         +' FROM PricebookEntry WHERE PriceBook2.IsStandard=true ';
         List<PricebookEntry> filterList;
        if(familyname =='All') { 
            filter+= 'AND Product2.Family != NULL AND Name LIKE \'%' + searchtext + '%\'';
        } else {   //get the filtered list 
            filter+= 'AND Product2.Family= \''+familyname +'\' AND Name LIKE \'%' + searchtext + '%\'';
        }
        filterList = DataBase.query(filter);
        List<ProductWrapper> wrapList = new List<ProductWrapper>();
         ProductWrapper wrap;    
        for(PricebookEntry prod : filterList){
            wrap = new ProductWrapper();
            wrap.id = prod.Product2.Id;
            wrap.name=prod.Name;
            wrap.ImageId=prod.Product2.Image_ID__c;
            wrap.Family=prod.Product2.Family;
            wrap.Price=prod.UnitPrice;
            wraplist.add(wrap);
        }
        return wraplist;
    }
    
CharuDuttCharuDutt
Hii Prakhyat sapra 
Try Below Class 100% coverage
@isTest
public class getFilterProductclsTest {
    @isTest
    public Static void UnitTest(){
        Product2 pro = new Product2(Name = 'iPhone X', Family = 'All');
        Insert pro;
        Product2 pro2 = new Product2(Name = 'iPhone XS', Family = 'Mobile');
        Insert pro2;
        
      
        Pricebook2 standardPricebook = new Pricebook2(
            Id = Test.getStandardPricebookId(),
            IsActive = true
        );
        
 
        Update standardPricebook;
        

        standardPricebook = [SELECT Id, IsStandard FROM Pricebook2 WHERE Id = :standardPricebook.Id];

        System.assertEquals(true, standardPricebook.IsStandard);
        
        PricebookEntry pbe = new PricebookEntry(
            Pricebook2Id = standardPricebook.Id,
            Product2Id = pro.Id,
            UnitPrice = 1020,
            IsActive = true
        );
        Insert pbe;
        getFilterProductcls.getFilterProduct('All', 'iPhone X');
        getFilterProductcls.getFilterProduct('Mobile', 'iPhone XS');
    }
}
Please Mark It As Best Asnwer If It Helps
Thank You!