You need to sign in to do that
Don't have an account?
Atiqah
Test class for Aura
Hi, I have LWC to help users search for products in my org. I need help with apex test code
public with sharing class FilterProduct { @AuraEnabled(cacheable=true) public static List<Product2> getproduct( String Name, String MaterialCode, String productType, ){ String query; String condition = (String.isNotBlank(Name)? 'Name LIKE \'' + '%' + Name + '%\'': ''); condition += (String.isNotBlank(MaterialCode)? (String.isNotBlank(condition) ? +' AND ' : '') +' Material_Code__c LIKE \'' + '%' +MaterialCode +'%\'': ''); condition += (String.isNotBlank(productType)? (String.isNotBlank(condition) ? +' AND ' : '') +' product_Type__c LIKE \'' + '%' +productType +'%\'': ''); System.debug('condition ' + condition); if (String.isNotBlank(condition)) { query = 'select name, Material_Code__c, product_Type__c from product2 WHERE ' +condition +' ORDER BY name limit 1000'; } else { query = 'select name, Material_Code__c, product_Type__c from product2 ORDER BY Name LIMIT 200'; } List<Product2> records = Database.query(query); return records; } }
Can you try the below test class.
Let me know if you face any issues.
If this solution helps, Please mark it as best answer.
Thanks,,
All Answers
Can you try the below test class.
Let me know if you face any issues.
If this solution helps, Please mark it as best answer.
Thanks,,
List<Product2> plist1= FilterProduct.getproduct(p.name,'','');
List<Product2> plist2= FilterProduct.getproduct('','','');
Your apex class has small correction. The method contains one extra , can you change it as below.
This should solve the issue.
Thanks,
You mean remove ',' after productType right? Yes, I already remove it. But I still get the errors
Are you able to save your apex class with out any issue and also test class?
If you still face issue can we connect over gmeet and resolve it .
Thanks,