How to fetch values from a map apex?

341    Asked by darsh_6738 in Salesforce , Asked on Jul 31, 2023

There is a map passed as a parameter of a given apex method. I want the values of the map. The apex method is given below:

@AuraEnabled
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));
    }
    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}}
How to get the value of the objectname or fieldname of the map?


Answered by Diana Campbell

The below map apex can be used to solve the error:

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; 

}The Salesforce Certification Training offered at JanBask Training provides experience like offline classes to help candidates master the Salesforce Development and Administration in a better way to face the tough job market scenario. The course guarantees job success and lets you qualify the certification exam through intensive, and expert-led virtual sessions and hands-on practical assignments. The course will teach you to create and configure the salesforce account to help you gather, extract, and examine the data relevant to the customer base. You can also avail the Force.com platform to create and use the advanced cloud apps with utmost confidence.



Your Answer

Interviews

Parent Categories