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
Genious007Genious007 

Text class coverage

Hi devs,
need some help to cover the below lines in red. I am stuck at 72%.
thanks in advance.

lines to cover
Maharajan CMaharajan C
Hi Mahmood,

in the searchResults there is no data... So it's not moving forward...

Try to pass the data in searchResults list... If there is any soql query filling this wrapper list then you have to add those data in test class...

Thanks,
Maharajan.C
AbhinavAbhinav (Salesforce Developers) 
You have already added debug statement for searchResults , Check the logs for it if there is any data as @Maharajan also pointed out


Check this for more inputs regarding similar scenario:

https://salesforce.stackexchange.com/questions/244794/how-do-i-increase-my-code-coverage-or-why-cant-i-cover-these-lines

Thanks!
Genious007Genious007
thanks, both, I appreciate that.

for some reason, the search results always come back as null. even there is 1 record inserted by the test class.
// Create a PageReference to the VF page being tested
        PageReference pageRefLh = Page.IRPBatchDonorAllocationLivelihood;
        test.setCurrentPage(pageRefLh);

        // Create an instance of the searchCriteria to test all
        // get/set methods and the BuildWhereClause() method
        searchCriteria  critClassLh = new searchCriteria();

        // Call the various Get/Set methods to test these
        // nothing to check for, just want to run the code
        system.debug(critClassLh.getInputDateFormat());
        critClassLh.getSearchField();
        critClassLh.getSearchOperator();
        critClassLh.getSearchValue();
        critClassLh.getLogical();
        critClassLh.getSearchValue();
        critClassLh.seterrMsg('');
        critClassLh.setLogical('AND');

        // Test all possible combinations of Fields and Operators
        List<SelectOption> operators = critClassLh.getOperatorSelectList();
        Set <String> fields = new Set<String>{'STRING/Field1', 'DATE/Field2', 'DATETIME/Field3',
            'PICKLIST/Field4', 'MULTIPICKLIST/Field5', 'EMAIL/Field6', 'PHONE/Field7',
            'DOUBLE/Field8', 'CURRENCY/Field9', 'BOOLEAN/Field10', 'TEXTAREA/Field11'};
                            
        Set <String> values = new Set<String>{'abcde', '12/12/2007', '12/12/2007 16:00:00', 'agh', 'abcd, efgh, ijkl','abc@abc.com','01215437689',
            '1.25678','12.00', 'true', 'NEXT 3 WEEKS'};

	           
         // Three nested loops - Fields, Operators, Values
        // nothing to check for, just want to run the code
        // Can look through the Test results for Debug entries if needed
        for (string f : fields) {
            critClassLh.setSearchField(f);
            for (SelectOption ops : operators) {
                critClassLh.setSearchOperator (ops.getValue());
                for (string v : values) {
                    critClassLh.setSearchValue (v);
                    //System.debug(f + ' ' + ops.getValue() + ' ' + v + ' :' + critClassLh.buildWhereClause(true) + ' - ' + critClassLh.geterrMsg());
                }
            }
        }

        // Create an instance of the page controller to test its methods
        IRPBatchDonorAllocationLivelihood cntrlrLh = new IRPBatchDonorAllocationLivelihood();
            
        // Call the various Get/Set methods to test these
        // nothing to check for, just want to run the code
        cntrlrLh.testMode = true;     // enable test mode to limit query results
        cntrlrLh.setSetDebugModeFALSE(true);
        cntrlrLh.setSetDebugModeTRUE(true);
        cntrlrLh.getSetDebugModeTRUE();
        cntrlrLh.getSetDebugModeFALSE();
        cntrlrLh.setSetDebugModeFALSE(true);
        cntrlrLh.setSetDebugModeTRUE(true);
        cntrlrLh.getInputDateFormat();
        cntrlrLh.optShowInactiveUsers = true;

        cntrlrLh.getsearchFields();
        cntrlrLh.getsearchCriteria();
        cntrlrLh.getSearchResults();
        cntrlrLh.getShowBlockIfResults();

        // Create a search criteria that must succeed
     
        cntrlrLh.criteriaLine[1].setSearchField('STRING/Orphan__r.Gender__c');
        cntrlrLh.criteriaLine[1].setSearchOperator ('eq');
        cntrlrLh.criteriaLine[1].setSearchValue ('Male');
        System.Debug('1'+cntrlrLh.criteriaLine[1].buildWhereClause(true));
        System.assertEquals('', cntrlrLh.criteriaLine[1].geterrMsg());

            
       system.debug('cntrlrLh -'+ cntrlrLh);
        // Run the Search against this criteria
        PageReference cntrlrResult = cntrlrLh.doSearch();
        
           system.debug('             ');
            system.debug('=== DEBUG === Results returned:' + cntrlrLh.searchResults.size());
            system.debug('             ');
			

			
search size is zero