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 All i need Apex test class for the below code please help me!!!

public with sharing class AskEddCaseInfo {
    @AuraEnabled(Cacheable=true)
    public static Map<String,Object>  getInitData(){
        Map<String,Object> returnMap = new Map<String,Object>();
        Map<String, Object> categories = AskEDD_HomeCategoriesCtrl.fetchTitleNames();
        Map<String, List<Map<String, String>>> subcategories =PickListUtility.getDependentPicklistOptions('Case','Sub_Category__c');
        returnMap.put('categories',categories);
        returnMap.put('subCategories',subcategories);
        return returnMap;
    }
    // @AuraEnabled(Cacheable=true)
    // public static List<Case> getTopic(String category,String subcategory){
    //     List<Case> topicList;
    //     if(category !='' && subcategory !=''){
    //         topicList = [Select Subject from Case where Category__c =:category and Sub_Category__c =:subcategory];
    //     }
    //     return topicList;
    // }

}
Best Answer chosen by SIVA KUMAR 507
Suraj Tripathi 47Suraj Tripathi 47

Hi Siva,

I think this is class Name "AskEDD_HomeCategoriesCtrl" and this is method "fetchTitleNames" similarly 

PickListUtility.getDependentPicklistOptions('Case','Sub_Category__c');

You just need to satisfy this condition "Map<String, Object> categories" so insert those object which you are querying in this method "fetchTitleNames". and similarly for getDependentPicklistOptions.

You can take reference from the below code.

//Class
global class AccountData{
    @AuraEnabled(Cacheable=true)
    public static List<Account>  getInitData(){
         List<Account> acList=AccountReturn.findData();
         return acList;
       
    }
}
retrun class
public class AccountReturn{
    
    public static List<Account> findData(){
         return [select id from Account limit 10];
        }
    }
//Test Class
@isTest
public class AccountDataTest {
    
   @testSetup static void fetchRecords(){
        Account ac=new Account();
       ac.Name='Test';
       insert ac;
       test.startTest();
       AccountData.getInitData();
       test.stopTest();
    }
}


Please mark it as the Best Answer if your query is solved.

Thank You.

All Answers

Suraj Tripathi 47Suraj Tripathi 47

Hi Siva,

I think this is class Name "AskEDD_HomeCategoriesCtrl" and this is method "fetchTitleNames" similarly 

PickListUtility.getDependentPicklistOptions('Case','Sub_Category__c');

You just need to satisfy this condition "Map<String, Object> categories" so insert those object which you are querying in this method "fetchTitleNames". and similarly for getDependentPicklistOptions.

You can take reference from the below code.

//Class
global class AccountData{
    @AuraEnabled(Cacheable=true)
    public static List<Account>  getInitData(){
         List<Account> acList=AccountReturn.findData();
         return acList;
       
    }
}
retrun class
public class AccountReturn{
    
    public static List<Account> findData(){
         return [select id from Account limit 10];
        }
    }
//Test Class
@isTest
public class AccountDataTest {
    
   @testSetup static void fetchRecords(){
        Account ac=new Account();
       ac.Name='Test';
       insert ac;
       test.startTest();
       AccountData.getInitData();
       test.stopTest();
    }
}


Please mark it as the Best Answer if your query is solved.

Thank You.

This was selected as the best answer
SIVA KUMAR 507SIVA KUMAR 507
Hi Suraj,
Thanks for your reply.
i have another apex class i don't know to write test class can you help on that please?