0

After writing the soql apex class, I am having a hard time writing the test code.

I'm trying to connect the soqlapex class and method to the test code, but I keep getting errors.

I newly declared a map in the test code, but I don't think I know how to get a parameter in this part.

Map<String, Object> newTest = testCont.testCase(testResult.list);

.list has an error line and I really don't know why.

Could you help us with this?

Here is my origin class

public with sharing class FilteredController {
    @AuraEnabled(cacheable=true)
    public static Map<String, Object> testCases(
        decimal exDimLength,
        decimal exDimLengthRange)
{
  
  String exDimLengths = String.valueOf(exDimLength);
  
  String query;
  
  String condition = (String.isNotBlank(exDimLengths) 
    ? ' ExternalDimensionLength__c <= ' +  ( exDimLength  + exDimLengthRange ) + ' AND ExternalDimensionLength__c >= ' + ( exDimLength - exDimLengthRange )
    : '');  

String columns = 'ID, SummaryNumber__c, Name, ExternalDimensionLength__c ';

    if (String.isNotBlank(condition)) {
        query =
                ' SELECT ' + columns + ' FROM Summary__c WHERE ' +
                condition;
    } else {
        query =  ' SELECT ' + columns + ' Summary__c ORDER BY NAME ';
    }


    List<Summary__c> records = Database.query(query);
    System.debug('records' + records);

    Map<String, Object> output = new Map<String, Object>();
    output.put('list', records);

    return output;

Here is my Test Code

@isTest
private class FilteredController_Test {
    @isTest
    private static void FilteredController_Test() {

        Summary__c records = new Summary__c();
        insert records;

        Map<String, Object> testResult = new Map<String, Object>();
        testResult.put('list', records);

        System.debug('testResult'+ testResult);

        FilteredController testCont = new FilteredController();
        Map<String, Object> newTest = testCont.testCase(testResult.list);

        
        System.Test.startTest();

        System.Test.stopTest();

    }

2
  • Your main method name is testCases and it is not having any parameters. Can you try calling the method without any parameters? Aug 12, 2022 at 3:43
  • Thank you! problem solved!
    – Yeonbi Ji
    Aug 12, 2022 at 5:07

0

You must log in to answer this question.

Browse other questions tagged .