Hot answers tagged

3

A map always has unique key values. Where you have multiple objects that could share the same key, you must make the map's values allow for this. For example, here I would make your Map<string,object> FinalMap actually Map<string,List<Object>> finalMap. Now you would populate it thus: for (Object obj : arr) { List<Object> entries ...


2

Map<String, Object> fieldMapLevel_0 = (Map<String, Object>)fieldMap.get('Accts'); The value of the key Accts in your JSON is a List, not a Map: String jsonPayLoad = '{"Accts":[{"Name":"ABC","Exp":25,"Languages":[{"Name":"Apex","version": []},{"Name":&...


1

If I have two Map<String, List<Object>> maps and I want to merge them, I can't just use: Map<String, List<Object>> x = ...; Map<String, List<Object>> y = ...; Map<String, List<Object>> z = new Map<String, List<Object>>(); z.putAll(x); z.putAll(y); This won't merge lists from x with lists from y ...


1

If you always use the same (partial match) criteria for finding values (here you match the Text value), the best solution is to actually use a Map not a List. Something like this: public class SelectItem { public String Text { get; set; } public String Value { get; set; } } public void FooMethod() { Map<String, SelectItem> items = new Map&...


1

The arrow functions don't exist in Apex. This is plain JavaScript. You can conceptually find an element if you already have it: SelectOption[] options = new SelectOption[] { new SelectOption('a','a'), new SelectOption('b','b') }; SelectOption target = new SelectOption('b','b'); System.assertEquals(1, options.indexOf(target)); This operation is ...


Only top voted, non community-wiki answers of a minimum length are eligible