You need to sign in to do that
Don't have an account?
Mandar 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];
}
}
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];
}
}
Note: Replace "recordTypeLabel" with the label of record type present in your org on Sobject 'Account'
other wise it will fail.