I'm having issues understanding some concepts of Object in apex and trying to write a test class for it. Here is my class
global void myLeadsCities(Map<String,Object> inputJsonMap) {
Set<String> leadCities = new Set<String>();
List<Object> objs = (List<Object>)inputJsonMap.get('leads');
for (Object o : objs) {
Map<String, Object> leadFields = (Map<String, Object>)o;
String city = (String)leadFields.get('city');
}
}
Test Class:
@isTest
global class LeadCitiesTest {
@isTest
static void testMethod() {
List<CustomObj> objs = new List<CustomObj>();
CustomObj o = new CustomObj('New York');
CustomObj o1 = new CustomObj('Boston');
objs.add(o);
objs.add(o1);
List<Object> anyObj = new List<Object>();
anyObj = (List<Object>) objs;
Map<String, Object> inputMap = new Map<String, Object>();
inputMap.put('city', anyObj);
Test.startTest();
LeadInfo leadDedup = new LeadInfo();
leadDedup.myLeadsCities(inputMap);
Test.stopTest();
}
public class CustomObj {
public String city;
public customObj(String c) {
city = c;
}
}
}
ERROR: Message Invalid conversion from runtime type LeadCitiesTest.CustomObj to Map<String,ANY>
I understand CustomObj is not Object but need help with the test coverage here.