How to get values from a map apex?
I have a map passed as a parameter of an apex method. In this method I need to get the values of the map. Here is the apex method :
@AuraEnabled
public static String manageFilters(Maplines){ System.debug('### lines : ' + lines);
System.debug('### lines.values() : ' + lines.values());
for(String key : lines.keySet()){
System.debug('### lines.get(key) : ' + lines.get(key));
System.debug('### >>> ' + lines.get(key));
}
return null;
}
The map lines is not null and contains some values, here is what I can see in the system debug of lines :
{0={FieldName=AccountId, ObjectName=Opportunity, Operator=<, Value=dfg}}
(Potentially, there could be more than one value)
My question is, how can I get, for example, the value of the 'ObjectName' or the value of the 'FieldName' of this map ?
You may use a Map apex for this:
public static String manageFilters(Map lines){
System.debug('### lines : ' + lines);
System.debug('### lines.values() : ' + lines.values());
for(String key : lines.keySet()){
System.debug('### lines.get(key) : ' + lines.get(key));
System.debug('### >>> ' + lines.get(key));
Map test = (Map)lines.get(key);
System.debug('### test ' + test);
System.debug('### test ' + test.get('ObjectName'));
}
return null;
}