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
Shruti VishShruti Vish 

Want to write the test class for below

    @AuraEnabled
    public static String getSearchResult(String patientId , String searchTerm , String listName){
        Map<Integer , String> mapIndexOfDynamicList = new Map<Integer , String>();
        Map<String , List<Object>> mapSearchResult = new Map<String , List<Object>>();
        Map<String , Map<String , String>> mapFieldApi = new Map<String , Map<String , String>>();
        Map<String , Map<String , String>> mapLinkRef = new Map<String , Map<String , String>>();
        List<String> lstFieldApi = new List<String>();
        List<String> lstDataDomainQuery = new List<String>();
        List<String> lstArg = new List<String>();
        List<Dynamic_List__c> lstDynamicList = new List<Dynamic_List__c>();
        Integer index = 0;
       
        lstArg.add(patientId);
        String baseString = 'FIND \'' + searchTerm  + '\' IN ALL FIELDS  RETURNING ';
 
        if(String.isNotBlank(listName))
            lstDynamicList = [SELECT Id, Name, objectAPIName__c, WhereClause__c, SOSL_whereClause__c, Order_By__c, searchIndex__c,
                            (SELECT Id, Name, fieldAPIName__c, isLink__c, Link_Reference__c, Detail_Page__c FROM Dynamic_List_Fields__r ORDER BY index__c)
                        FROM Dynamic_List__c WHERE searchIndex__c != null AND Name =: listName ORDER BY searchIndex__c asc];
        else
            lstDynamicList = [SELECT Id, Name, objectAPIName__c, WhereClause__c, SOSL_whereClause__c, Order_By__c, searchIndex__c,
                            (SELECT Id, Name, fieldAPIName__c, isLink__c, Link_Reference__c, Detail_Page__c FROM Dynamic_List_Fields__r ORDER BY index__c)
                        FROM Dynamic_List__c WHERE searchIndex__c != null ORDER BY searchIndex__c asc];
                       
        for (Dynamic_List__c dl : lstDynamicList)
        {
            if(!mapIndexOfDynamicList.containsKey((Integer)dl.searchIndex__c)){
                if(String.isNotBlank(listName))
                    mapIndexOfDynamicList.put(1 , dl.Name);
                else
                    mapIndexOfDynamicList.put((Integer)dl.searchIndex__c , dl.Name);
            }
               
            lstFieldApi         = new List<String>();
            String detailPage   = '';
            String whereClause  = '';
            for (Dynamic_List_Field__c dlf : dl.Dynamic_List_Fields__r){
                lstFieldApi.add(dlf.fieldAPIName__c);
                if(dlf.isLink__c)
                {
                    lstFieldApi.add(dlf.Link_Reference__c);
                    //detailPage : Used to maintain value of the navigation , when clicked on hyperlink
                    detailPage = dlf.Detail_Page__c == null ? '' : dlf.Detail_Page__c;
                   
                    if(!mapLinkRef.containsKey(dl.Name))
                        mapLinkRef.put(dl.Name , new Map<String , String>());
                    mapLinkRef.get(dl.Name).put(dlf.fieldAPIName__c , dlf.Link_Reference__c+'#'+detailPage);
                }
               
                if(!mapFieldApi.containsKey(dl.Name))
                    mapFieldApi.put(dl.Name , new Map<String , String>());
                mapFieldApi.get(dl.Name).put(dlf.fieldAPIName__c , dlf.Name);
            }
            whereClause = String.isNotBlank(dl.SOSL_whereClause__c) == true ? string.format(dl.SOSL_whereClause__c, lstArg) : string.format(dl.WhereClause__c, lstArg);
            whereClause = whereClause.replace('\"','\'');
           
            if(String.isNotBlank(listName))
                lstDataDomainQuery.add(dl.objectAPIName__c + '(' + string.join (lstFieldApi, ',') + ' WHERE ' + whereClause + ' )');
            else
                lstDataDomainQuery.add(dl.objectAPIName__c + '(' + string.join (lstFieldApi, ',') + ' WHERE ' + whereClause + ' LIMIT 10 )');
        }
       
        //Looping across list of subQuery to process SOSL one by one, as we have same objects with different where clauses for multiple Data Domains
        for(String subQuery : lstDataDomainQuery){
            String searchString = '';
            searchString = baseString + subQuery;
            List<List<sObject>> searchList = search.query(searchString);
            index++;
            //Loop through records fetched by SOSL Query
            mapSearchResult = getDataDomainResult(index, searchList , mapIndexOfDynamicList, mapFieldApi, mapLinkRef, mapSearchResult);
        }
        System.debug('mapSearchResult :: ' + mapSearchResult);
        return Json.serialize(mapSearchResult);
    }
   
    public static Map<String , List<Object>> getDataDomainResult(Integer index , List<List<sObject>> searchList , Map<Integer , String> mapIndexOfDynamicList ,
                                                            Map<String , Map<String , String>> mapFieldApi, Map<String , Map<String , String>> mapLinkRef,
                                                            Map<String , List<Object>> mapSearchResult){
        for(List<sObject> lstSObj : searchList){
            String dlName = mapIndexOfDynamicList.get(index);
            List<Map<String , String>> lstResultRecord = new List<Map<String , String>>();
           
            //Loop through each record
            for(sObject SObj : lstSObj){
                Map<String , String> mapFieldToValue = new Map<String , String>();
               
                //Loop through each value to map the field api name with its display name maintained in Dynamic list Field and value fetched
                for(String api : mapFieldApi.get(dlName).keyset()){
                    String displayVal = '';
                    String linkrefApi = '';
                    String linkrefRedirectPage = '';
                    //Check if the value should be an hyperlink or just a value
                    if(mapLinkRef.containsKey(dlName) && mapLinkRef.get(dlName).containsKey(api)){
                        linkrefApi  = mapLinkRef.get(dlName).get(api).split('#')[0];
                        //If it is a hyperlink, get the redirect page for the hyperlink
                        if(mapLinkRef.get(dlName).get(api).split('#').size() > 1)
                            linkrefRedirectPage = mapLinkRef.get(dlName).get(api).split('#')[1];
                        else
                            linkrefRedirectPage = dlName;
                    }
                    //Get the fetched values against the api
                    if(SObj.getPopulatedFieldsAsMap().containsKey(api)){
                        if(linkrefApi != '')
                            displayVal = '<button name= "' + linkrefRedirectPage + '" value = "' + dlName + '" id="'+ String.valueOf(SObj.getPopulatedFieldsAsMap().get(linkrefApi)) + '" title= "'+ String.valueOf(SObj.getPopulatedFieldsAsMap().get(api)) + '" class=\'linkbutton\'>' + String.valueOf(SObj.getPopulatedFieldsAsMap().get(api)) + '</button>';
                        else
                            displayVal = String.valueOf(SObj.getPopulatedFieldsAsMap().get(api));
                    }
                    //Populate the map with field display name and value
                    mapFieldToValue.put(mapFieldApi.get(dlName).get(api) , displayVal);
                }
                //Add all records to the list
                lstResultRecord.add(mapFieldToValue);
            }
            if(!lstResultRecord.isEmpty())
                mapSearchResult.put(dlName , lstResultRecord);
        }
        return mapSearchResult;
    }
     @AuraEnabled
    public static void updateUserSession(String currentPage, String fname, String lname, String cin, String dob, String gender){
        UtilityGeneral.updateUserSession(currentPage, fname, lname, cin, dob, gender);
    }
    @AuraEnabled
    public static void logHIPAAAudit(String acctId ,String hc_DataComponent){
        HIPAAAuditLogin__c hipaaauidLogObj=HIPAAAuditLogin__c.getInstance(hc_DataComponent);
        if(hipaaauidLogObj!=null && acctId != null )
        {
            HIPAAAuditLogController.logAccess(acctId, hc_DataComponent);
        }
    }
}
 
Rahul KumarRahul Kumar (Salesforce Developers) 
Hi, I hope it will be helpful.

Please mark it as best answer if the information is informative.

Best Regards
Rahul Kumar
 
Shruti VishShruti Vish
I am unable to write test class for above plz can anyone help me out