+ Start a Discussion
Mandar Kulkarni 13Mandar Kulkarni 13 

Need help in writing a test class.

Please help in writting test class for below controller 
Controller : 
public with sharing class accountLst {

      public static Map<Id, String> recordtypemap {get;set;}
    
   @AuraEnabled        
    public static List<String> fetchRecordTypeValues(){
        List<Schema.RecordTypeInfo> recordtypes = Account.SObjectType.getDescribe().getRecordTypeInfos();    
        recordtypemap = new Map<Id, String>();
        for(RecordTypeInfo rt : recordtypes){
            if(rt.getName() != 'Master')
            recordtypemap.put(rt.getRecordTypeId(), rt.getName());
        }        
        return recordtypemap.values();
    }
    
    @AuraEnabled
    public static Id getRecTypeId(String recordTypeLabel){
        Id recid = Schema.SObjectType.Account.getRecordTypeInfosByName().get(recordTypeLabel).getRecordTypeId();        
        return recid;
    }    
    
    @AuraEnabled
    public static List<account> findByName(String cName){
        
        String nm='%'+cName+'%';
        return [SELECT id, Name, Phone, Post_Code__c, Categories_del__c FROM Account where Name LIKE :nm LIMIT 20];
          
    }
}
mohdAnasmohdAnas
Hi,
 
​@isTest
public class accountLstTest {
    
    @isTest
    public static void accountLstTestmethod(){
        
        accountLst.fetchRecordTypeValues();
        accountLst.findByName('Test');
        accountLst.getRecTypeId('recordTypeLabel');
    } 
}

Note: Replace "recordTypeLabel" with the label of record type present in your org on Sobject 'Account'
other wise it will fail.