You need to sign in to do that
Don't have an account?
swain 10
Test Class for dependent picklist
How to write Test Class for dependent picklist methods?
@AuraEnabled
public static List<String> getDepStates(String objectType, String parentField, String childField,String search){
List<String> optionStates = new List<String>();
PicklistFieldController controller = new PicklistFieldController();
Map<String,List<String>> valueMap = PicklistFieldController.getDependentOptionsImpl(objectType,parentField,childField);
for(String contr : valueMap.keySet()){
// System.debug('CONTROLLING FIELD : ' + contr);
//System.debug('DEPENDENT VALUES ... : ' + valueMap.get(contr));
if(search==contr){
optionStates=valueMap.get(contr);
}
}
return optionStates;
}
@AuraEnabled
public static List<String> getPickList(String field,String objectName){
List<String> lstPickvals=new List<String>();
Schema.SObjectType targetType = Schema.getGlobalDescribe().get(objectName);
Sobject Object_name = targetType.newSObject();
Schema.sObjectType sobject_type = Object_name.getSObjectType();
Schema.DescribeSObjectResult sobject_describe = sobject_type.getDescribe();
Map<String, Schema.SObjectField> field_map = sobject_describe.fields.getMap();
List<Schema.PicklistEntry> pick_list_values = field_map.get(field).getDescribe().getPickListValues();
for (Schema.PicklistEntry a : pick_list_values) { //for all values in the picklist list
lstPickvals.add(a.getValue());//add the value to our final list
}
return lstPickvals;
}
}
@AuraEnabled
public static List<String> getDepStates(String objectType, String parentField, String childField,String search){
List<String> optionStates = new List<String>();
PicklistFieldController controller = new PicklistFieldController();
Map<String,List<String>> valueMap = PicklistFieldController.getDependentOptionsImpl(objectType,parentField,childField);
for(String contr : valueMap.keySet()){
// System.debug('CONTROLLING FIELD : ' + contr);
//System.debug('DEPENDENT VALUES ... : ' + valueMap.get(contr));
if(search==contr){
optionStates=valueMap.get(contr);
}
}
return optionStates;
}
@AuraEnabled
public static List<String> getPickList(String field,String objectName){
List<String> lstPickvals=new List<String>();
Schema.SObjectType targetType = Schema.getGlobalDescribe().get(objectName);
Sobject Object_name = targetType.newSObject();
Schema.sObjectType sobject_type = Object_name.getSObjectType();
Schema.DescribeSObjectResult sobject_describe = sobject_type.getDescribe();
Map<String, Schema.SObjectField> field_map = sobject_describe.fields.getMap();
List<Schema.PicklistEntry> pick_list_values = field_map.get(field).getDescribe().getPickListValues();
for (Schema.PicklistEntry a : pick_list_values) { //for all values in the picklist list
lstPickvals.add(a.getValue());//add the value to our final list
}
return lstPickvals;
}
}
1) https://trailhead.salesforce.com/modules/apex_testing
Pleasse check below post sample test class
1) http://amitsalesforce.blogspot.com/2015/06/best-practice-for-test-classes-sample.html
Also please check below post
1) https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_qs_test.htm
2) https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_testing_example.htm
Sample test class for you NOTE:- Please pass field API name
Let us know if this will help you