You are really working uphill by doing this all untyped, but you can get the value you want this way:

list<Object> l = (list<Object>) meta.get('addressDetails');
map<String,Object> m = (map<String,Object>) l[0];
Integer i = (Integer) m.get('addressId');

Honestly, if you make use of the Apex type system, you will have an easier time working with the data. If you create a class for the incoming data structure, abbreviated as:

public class Meta{
   public list<addressDetail> addressDetails {get; set;} 

   public class addressDetail{
       public Integer addressId {get; set;}
   }   
}

you will be able to access the data from your JSON strings as so:

Meta MyMeta = (Meta) JSON.deserialize(viewPersonValue,Meta.class);
system.debug(MyMeta.addressDetails[0].addressId);
Answer from martin on Stack Exchange
🌐
Davide Gammone
gammone.com › home › programming
How to create a Map in Salesforce with Keys = Fields Name and Values​ = Query Result | Programming | Davide Gammone
February 23, 2019 - String stringAcc = JSON.serialize(record); Map<String, Object> mapAcc = (Map<String, Object>)JSON.deserializeUntyped(stringAcc); mapAcc.remove('attributes'); Apex code and query for many records: List<Account> record = [SELECT Name, Phone FROM Account LIMIT 2]; List<Map<String, Object>> listTotal = new List<Map<String, Object>>(); for(Account forAcc : record) { system.debug(forAcc.get('Name')); system.debug(forAcc.get('Phone')); forAcc.put('Phone', '0811234567'); String stringAcc = JSON.serialize(forAcc); system.debug(stringAcc); Map<String, Object> mapAcc = (Map<String, Object>)JSON.deseriali
Discussions

apex - Creating a Map with String, Object combination - Salesforce Stack Exchange
I have a List of String. This list consist of accountNumbers from Account Object. List accountNumList. I have a child object XYZ__c, which is child of Account Object. XYZ__c object ha... More on salesforce.stackexchange.com
🌐 salesforce.stackexchange.com
Using Maps in Apex (beginner)
To visualize it, imagine a Map of students and their grades: ... The names there would be the keys and the numbers would be the values. It's fine that john and sandy have the same value, but you couldn't add another john, because keys must be unique. Keys and values can be other types besides strings and numbers, including collections and other objects... More on reddit.com
🌐 r/salesforce
7
4
September 23, 2020
dictionary - APEX: Assigning a Map without a Key to a List - Stack Overflow
Sorry for the newbie question. Learning Apex here. Been working on an issue for several hours and can't seem to needle it out. I have a JSON that I need converted to a List... the JSON is retrie... More on stackoverflow.com
🌐 stackoverflow.com
Can't return Salesforce MAP<String, Object> using get - Stack Overflow
The problem is that key of your map is Id, is not String, you can see it from first debug message. ... Sign up to request clarification or add additional context in comments. ... Save this answer. ... Show activity on this post. Unfortunately for your use case what Pavel described is totally true http://www.salesforce.com/us/developer/docs/apexcode... More on stackoverflow.com
🌐 stackoverflow.com
🌐
Reddit
reddit.com › r/salesforce › using maps in apex (beginner)
r/salesforce on Reddit: Using Maps in Apex (beginner)
September 23, 2020 - Map<String, Map<String, String>> englishMap = new Map<String, Map<String, String>>(); englishMap.put('One', new Map<String,String>{'spanish' => 'Uno'}); englishMap.put('Two', new Map<String,String>{'spanish' => 'Dos'}); You might also add support for more languages. Maybe that is a dumb scenario, but most of the cases you need to understand how to return a value or a list of values, with a given input. You can have two objects and you want to map their fields.
Top answer
1 of 2
1

You cant convert the map to a list without an id. Alternatively why to convert it to List. Use the map itself. Below is a code example of how you can use it using your JSON response. For example, I want to insert this JSON response into the contact record, so I can map it using the MAP itself.:

@RestResource(urlMapping='/URIId/*') global class OwneriCRM {

@HttpPut
global static String UpdateOwnerinfo(){
    RestRequest req= RestContext.request;
    RestResponse res= RestContext.response;
    res.addHeader('Content-type','application/JSON');
    Map<String,Object> responseresult=new Map<String,Object>();
    Map<String,Object> results= (Map<String,Object>)JSON.deserializeUntyped(req.requestBody.toString());
     List<contact> insertList = new List<contact>();
    
    for (String key : results.keySet()){
    System.debug(results.get(key));
    contact c= new contact();
    c.ContactField__C = results.get(id);
    c.ContactField1__C = results.get(city);
    c.ContactField2__C = results.get(conference);
    c.ContactField3__C = results.get(division);
    c.ContactField3__C = results.get(full_name);
    c.ContactField3__C = results.get(name);
    insertList.add(c);
    
    }
    if(!insertList.Isempty()){
        update insertList;
    }
2 of 2
0

Question can be disregarded. Not sure if there is a way to withdraw the question.

Question was based on the fact that previous APIs had been sent in the following format:

{"data": {"more stuff": "stuff"} }

And the map key was 'data' with a list. In this scenario, the whole API was a list and the keys to the map were set in place with the actual values instead.

Find elsewhere
🌐
Forcetalks
forcetalks.com › salesforce-topic › how-can-i-get-value-in-map-from-json-in-apex
How can I get value in MAP from JSON in Apex? - Salesforce® Discussions - Forcetalks
How can I get value in MAP from JSON in Apex? Pooja replied 6 years, 1 month ago 3 Members · 2 Replies · 2 Replies · Member July 9, 2020 at 3:54 PM · Hi, Map<String, Object> m = (Map<String, Object>) JSON.deserializeUntyped(jsonInput); Map<String, Object> m2 = (Map<String, Object>) m.get('info5'); List<decimal> d = new List<decimal>(); for(String s:m2.keyset()) { decimal t = (decimal) m2.get(s); d.add(t); } [adinserter block='9'] Member July 9, 2020 at 4:39 PM ·
🌐
JanbaskTraining
janbasktraining.com › home › salesforce maps: features, benefits & methods
Salesforce Maps: Features, Benefits & Methods
December 29, 2022 - A map is a collection of key-value pairs where each unique key maps to a single value. Map keys can be any primitive data type like string, integer,decimal, Id while values can be a primitive, sObject, collection type or an Apex object.
🌐
Panther Schools
pantherschools.com › home › salesforce › how to use map collection in salesforce?
How to use Map Collection in Salesforce? » Panther Schools
April 21, 2025 - Map is very powerful while using Apex Code in Salesforce · Map<String, String> countryCurrencies = new Map<String, String>();
🌐
Propicsignifi
propicsignifi.github.io › mapper-apex › docs › Mapping
Mapping - Mapper.apex
A Field Mapper Key is a path that specifies the exact field name of the object that we want to get the value from. Field Mapper keys can be nested. ... Here we have a . separated string that acts as the Field Mapper Key, which specifies the Name field of the object, under the field Account ...
🌐
S2 Labs
s2-labs.com › home › map initialization methods in apex
Map Initialization Methods In Apex | Salesforce Developer Tutorials
April 27, 2026 - Below are the different methods ... MyCustomObject__c obj2 = new MyCustomObject__c(Name = 'Object2'); Map<String, MyCustomObject__c> myMap = new Map<String, MyCustomObject__c>{ 'Key1' => obj1, 'Key2' => obj2 };...
🌐
Michael Soriano
michaelsoriano.com › home › blog › a few apex tips that i’ve picked up along the way
A few Apex tips that I've picked up along the way - Michael Soriano
April 23, 2022 - I know Apex is not a popular language, but the concepts are pretty universal. Almost guarantee, you will have to parse JSON for your applications. May it be from an API or accepting as parameters to your methods. The simplest JSON response is something like below: ... Map<String,Object> parsedResponse = ( Map<String,Object>) JSON.deserializeUntyped(jsonstr); System.debug(parsedResponse.get('key1')); //val1 System.debug(parsedResponse.get('key2')); //val2
Top answer
1 of 2
8

Looking in to this question, I realized that the type system is inherently broken. They have "fixed" Maps, it seems, but in a way that no longer lets you mix and match some types, especially Object.

The list class is still broken, however:

class c1 {

}
class c2 extends c1 {

}
c1[] s = new c2[0];

Generally speaking, unless/until they fix the problem, you won't be able to be polymorphic this way; your classes that intend to call this class would also need to use Map<Object, Object>, which will involve some casting.

One thought I had would be to create an interface like this:

public interface keyValueMap {
    Set<Object> getKeys();
    Object[] getValues();
    Object getKey(Object value);
    Object setKey(Object key, Object value);
}

And then create specific wrappers:

public class StringSObjectMap implements KeyValueMap {
    Map<String, SObject> values;
    public StringSObjectMap(Map<String, SObject> values) {
        this.values = values;
    }
    public StringSObjectMap() {
        values = new Map<String, SObject>();
    }
    public Set<Object> getKeys() {
        Set<Object> results = new Set<Object>();
        for(String value: values.keySet()) {
            results.add(value);
        }
        return results;
    }
    public Object[] getValues() {
        return (Object[])values.values();
    }
    public Object getKey(Object value) {
        return (Object)values.get((String)value);
    }
    public Object setKey(Object key, Object value) {
        return values.put((String)key, (SObject)value);
    }
}

Note that since we can't cast Set<SObject> to Set<Object>, we have to build a duplicate key set. Make sure you cache the results for performance reasons.

Finally, you can write your method to use the new interface:

public keyValueMap doSomething(keyValueMap inputMap) {

And to call it, you'd pass in the appropriate sub-wrapper:

keyValueMap results = doSomething(new StringSObjectMap(recordMap));

Depending on what you're doing, this may require additional post-processing to get the values back out.

You might also just leave the return type as Map<Object, Object> but you'll end up having to process the keys again, as demonstrated in the wrapper above. One additional step might help you here; you can pass in the type of return value you want:

public keyValueMap doSomething(keyValueMap inputMap, Type mapType) {
  keyValueMap results = (keyValueMap)mapType.newInstance();

Called as:

keyValueMap results = doSomething(new StringSObjectMap(recordMap), StringSObjectMap.class);

You could also create a custom Iterator, but this doesn't work in for-each loops (but you can use iter.next/iter.hasnext):

public class KeyValue {
  public Object key;
  public Object value;
  public KeyValue(Object k, Object v) {
    key = k;
    value = v;
  }
}

public class StringSObjectIter implements Iterable<KeyValue>, Iterator<KeyValue> {
    Map<String, SObject> values;
    String[] keys;
    public StringSObjectIter(Map<String, SObject> values) {
        this.values = values;
    }
    StringSObjectIter(StringSObjectIter copy) {
        values = copy.values;
        keys = new List<String>(values.keySet());
    }
    public Boolean hasNext() {
        return !keys.isEmpty();
    }
    public KeyValue next() {
        String k = keys.remove(0);
        return new KeyValue(k, values.get(k));
    }
    public Iterator<KeyValue> iterator() {
        return new StringSObjectIter(this);
    }
}

Which you can use in your method as:

public keyValueMap doSomething(Iterable<KeyValue> inputs) {
  Iterator<KeyValue> iter = inputs.iterator();
  while(iter.hasNext()) {
    KeyValue value = iter.next();
    ...

Calling method for this:

keyValueMap results = doSomething(new StringSObjectIter(recordMap));
2 of 2
3

No, there isn't a better way. With Set, you can hack around it to some extent. But with a Map, you care about the values, not just the keys, so you can't do it without looping.

Set<String> values = new Set<String>();
Set<Object> generic = new Set<Object>((List<Object>)new List<String>(values));

It's not immediately clear if this song and dance is even faster than looping anyway.

🌐
GitHub
gist.github.com › emoran › 4ea945ec3db32cc8c06b
Adding list values to apex map<String,List<Sobject>> · GitHub
Map<Id, List<Id>> userRoleToUsers = new Map<Id, List<Id>>(); for(User newUser : [SELECT UserRoleId FROM User LIMIT 50000]) { if(userRoleToUsers.containsKey(newUser.UserRoleId)) { userRoleToUsers.get(newUser.UserRoleId).add(newUser.Id); } else ...
🌐
Stack Exchange
salesforce.stackexchange.com › questions › 303039 › create-a-new-map-from-mapstring-mapstring-string-and-mapstring-mapstring-o
create a new map from map<string,Map<String,String>> and map<string,Map<String,Object>> in apex? - Salesforce Stack Exchange
6 Visualforce: apex:repeat and Map · 1 Match object from map and get its records · 1 Creating a Map with String, Object combination · 1 Get Unique keys map and Repeated keys map · 1 How to map afield of an object on a map · 0 Create map between api and record value ·
🌐
HIC GLOBAL SOLUTIONS
hicglobalsolutions.com › home › how to construct a json structure in maps using apex?
Know How To Construct JSON Structure In Maps Using Apex ?
October 3, 2024 - Construct JSON structure in maps helps yout to show data simply and efficiently with the details of an object the way you’ve always wanted it.