You need to sign in to do that
Don't have an account?
How to write test class for map<object,object>collection object
How to write test class for map<object,object>collection object please have a look the below code
@AuraEnabled
public static String createContactRecords(List<Object> lstObjects) {
For(Object obj : lstObjects) {
Map<Object, Object> mapContact = (Map<Object,Object>)obj;
If(mapContact.get('type') == 'string' ||
mapContact.get('type') == 'text' ||
mapContact.get('type') == 'textarea' ||
mapContact.get('type') == 'url' ||
mapContact.get('type') == 'phone' ||
mapContact.get('type') == 'email'
) {
If(mapContact.get('value') != null && String.valueOf(mapContact.get('value')) != '') {
objContact.put(String.valueOf(mapContact.get('field')), String.valueOf(mapContact.get('value')));
}
}
}
test class-
@isTest
public class ContactFormHandler_Test {
@isTest
public static void test(){
Account acc= new Account();
acc.Name = 'test';
insert acc;
contact con = new Contact();
con.LastName = 'test1';
insert con;
List<object> objList = (List<object>)json.deserializeUntyped('[{"field": "FirstName","type": "string", "value": "tedf"},{"field":"LastName", "type":"string", "value":"hgghjh"}]');
ContactFormHandler.createContactRecords(objList);
It show error - System.TypeException: Invalid conversion from runtime type Map<String,ANY> to Map<ANY,ANY>