I have an apex class like that :
@AuraEnabled
public static WrapperFilters manageFilters(Map<String, Object> lines){
Map<Object, Object> mapLineDetail = new Map<Object, Object>();
//iterate through inserted lines
for(String key : lines.keySet()){
mapLineDetail = (Map<Object, Object>)lines.get(key); //line where the test class fail
//other code like that :
if(mapLineDetail.get('ObjectName') == 'Account') {
//....
}
}
}
And here is the test method for this method :
@isTest static void manageFilters_Test() {
LCR01_AccountList.WrapperLine wrapLine = new LCR01_AccountList.WrapperLine();
wrapLine.ObjectName = 'Opportunity';
wrapLine.FieldName = 'Amount';
wrapLine.Operator = '<';
wrapLine.Value = '10000';
system.debug('### wrapLine : ' + wrapLine);
Map<String, Object> mapFilters = new Map<String, Object>();
String filter = '{FieldName=AccountId, FieldType=, ObjectName=Opportunity, Operator==, Value=0016E00000TIZUYQA5}';
Object myObj = filter;
System.debug('### myObj : ' + myObj);
mapFilters.put('1', myObj);
Test.startTest();
LCR01_AccountList.WrapperFilters wrap = LCR01_AccountList.manageFilters(mapFilters);
Test.stopTest();
}
The problem is when I run the test class I got this error :
System.TypeException: Invalid conversion from runtime type String to Map
I test many things but I can't get over this error. The test fail at the line indicated in the apex method mapLineDetail = (Map<Object, Object>)lines.get(key);
I specify that the code (apex class) actually works.