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
SIVA KUMAR 507SIVA KUMAR 507 

Hey Guys I need Test Class For the below Code please guys help me.a

Apex Class:
_______________
global with sharing class FlowListController {

    @AuraEnabled(cacheable=true)
    public static List<FlowDefinitionView> getFlowNamesApex(String filtersString) {

        String queryString = 'SELECT Id, ApiName, Label FROM FlowDefinitionView ';

        if (filtersString != null) {
            Map<String, List<String>> filters = (Map<String, List<String>>) JSON.deserialize(filtersString, Map<String, List<String>>.class);
            if (!filters.isEmpty()) {
                queryString += ' WHERE ';
                Boolean isFirst = true;
                for (String fieldName : filters.keySet()) {
                    List<String> values = filters.get(fieldName);
                    String negativeClause = fieldName.contains('!') ? (values.size() > 1 ? 'NOT ' : '!') : '';
                    String operator = values.size() == 1 ? '= ' : 'IN ';
                    String value = values.size() == 1 ? values[0] : '(\'' + String.join(values, '\',\'') + '\')';
                    queryString += (!isFirst ? ' AND ' : ' ') + fieldName.replace('!', '') + ' ' + negativeClause + operator + value;
                    isFirst = false;
                }
            }
        }

        return (List<FlowDefinitionView>) Database.query(queryString);
    }
}
Suraj Tripathi 47Suraj Tripathi 47

Hi Siva,

Please find the solution. "Hey Guys I need Test Class For the below Code please guys help me.a"

@isTest
private class FlowListControllerTest {
    static testMethod void getFlowNamesApexTest() {
       
          FlowDefinitionView obj = new FlowDefinitionView();
          obj.IsActive=true;
		  obj.Label='Account';
		  obj.ApiName='Account';
		  
		  insert obj;
		  
		  String filtersString='Account';
		  
		   test.startTest();
		   FlowListController.getFlowNamesApex(filtersString);
           test.stopTest();
     }
}

Note: Please pass the valid string "filtersString" as I am not passing correct data here.I mean you know this string "filtersString" which type of data has this  String "filtersString"

Please mark it as the Best answer so that other people would take reference from it.

Thank You

 

 

SIVA KUMAR 507SIVA KUMAR 507
HI Suraj, Thanks  For Your Reply.
When i tried to run the test class it showing errors.
User-added image