You need to sign in to do that
Don't have an account?
Prakhyat 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;
}
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;
}
Try Below Class 100% coverage Please Mark It As Best Asnwer If It Helps
Thank You!