Skip to main content

All Questions

Tagged with
Filter by
Sorted by
Tagged with
0 votes
1 answer
951 views

Tips to generalize code in apex with Map<string, set<string>> and Map<string, set<SObject>> and how to call method of SObject

I am working on some generalization of my code and I'm struggling with some cases which are irritating me because I think I'm having code duplicity. 1) I'm often working with some map<string, set&...
yeye's user avatar
  • 125
0 votes
2 answers
473 views

Is it possible to create a generic Map swapper?

I have a method: public Map<Object, Object> swap(Map<Object, Object> valueByKeyMap) { Map<Object, Object> keyByValueMap = new Map<Object, Object>(); for (Object key : ...
Brian Kessler's user avatar
1 vote
2 answers
2k views

Is it possible to convert Map<Object, List<Object>> to Map<Id, List<SomeConcreteSObject>> without a loop?

As a Salesforce developer, I am frequently working with Maps and am looking to abstract the process of generating maps from SObject lists. I've created the following helper class: private class ...
Brian Kessler's user avatar
-2 votes
1 answer
171 views

How to create a Map with generics Id and String?

How to create a Map<Id, String>([SELECT Id, Name from Account]);? The query returns Map<Id, Account>. I want to get a Map<Id, String> without using loops and without having to ...
lemdev's user avatar
  • 427
6 votes
2 answers
2k views

In Apex, can I detect if an Object is a Map, regardless of parameterized types?

When I declare a Map, I need to give the types, e.g.: Map<Id, SObject> sObjectByIdMap = new Map<Id, SObject>(); We can assign map to generic values as Objects: Object value = ...
Brian Kessler's user avatar
10 votes
2 answers
12k views

What is the best way to cast/convert Map<String, SObject> to Map<Object, Object> and back again?

To reduce code duplication, at the risk of type safety, I have some method: public Map<Object, Object> doSomething(Map<Object, Object> inputMap) { Map<Object, Object> outputMap; ...
Brian Kessler's user avatar
2 votes
1 answer
79 views

How can I abstract building maps from SObject Lists in a good way? [duplicate]

I frequently find I want/need to map a list of SObjects by a value other than it's own Id. So, I'd like to abstract this process to make it reusable. For example, I might want to map Contacts by ...
Brian Kessler's user avatar