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
santhiya duraisanthiya durai 

unable to cover code coverage

I have tried to cover below class but unable to cover even single % . Unable to figure out where/what I missed, Please anyone help me

Apex:

public with sharing class customSearchController { public static list<ICIX_V1__ICIX_Product__c> getContactList(string searchKey,string productType) { string sTempSearchKey = '%' + searchKey + '%'; //string sTempSearchKey = '%' + searchKey; // create Product list to store search result list<ICIX_V1__ICIX_Product__c> lstProduct = new list<ICIX_V1__ICIX_Product__c>(); // query Product records for(ICIX_V1__ICIX_Product__c oCon : [Select id,Name,Product_Number__c,ProductType__c,Parent_Name__c From ICIX_V1__ICIX_Product__c WHERE Product_Number__c LIKE : sTempSearchKey and ProductType__c=:productType limit 10]){ lstProduct.add(oCon);
}
return lstProduct;
} }

Test class:

@isTest public class customSearchController_Test { static testMethod void getContactListMethod() { try{ list<Account> acclist=new list<Account>(); Account acc=new Account(); acc.name='Hasbro Dev Stg Res 2'; acc.ICIX_V1__Status__c='Active'; acc.ICIX_V1__ICIX_ID__c='304078'; //acc.ICIX_V1__Internal__c=true; acclist.add(acc); insert acclist; string searchKey; string productType; list<ICIX_V1__ICIX_Product__c> lstProduct = new list<ICIX_V1__ICIX_Product__c>(); string sTempSearchKey = '%' + searchKey + '%'; ICIX_V1__ICIX_Product__c product1=Hasbro_TestDataFactory.createProduct()[0]; product1.Product_Number__c='C6119AV10'; product1.ProductType__c='ASSORTMENT'; lstProduct.add(product1); ICIX_V1__ICIX_Product__c product2=Hasbro_TestDataFactory.NewProduct(); product2.Product_Number__c='C6119AV10'; product2.ProductType__c='ASSORTMENT'; lstProduct.add(product2); insert lstProduct; customSearchController.getContactList('product2.Product_Number__c','product2.ProductType__c'); } catch(Exception e){
} } }


 
ANUTEJANUTEJ (Salesforce Developers) 
Hi Santhiya,

As you are sending the setings you can try changing the statement customSearchController.getContactList('product2.Product_Number__c','product2.ProductType__c'); to customSearchController.getContactList(product2.Product_Number__c,product2.ProductType__c);

Let me know where you are facing the issue also, I would suggest you to have a system.assert statement as you are returning list of records having a assert value could cover the return statement in the class method.

Here are the links to trailhead module that could help you in understanding all the elements in test class.

>> https://trailhead.salesforce.com/content/learn/modules/apex_testing

I hope this helps and in case if this comes handy can you please choose this as best answer so that it can be useful for others in the future.

Regards,
Anutej