Linked Questions

2 votes
1 answer

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
17 votes
4 answers

How to find out if an Object is a collection or single value?

I have some dynamic SOQL code in which I'd like to identify whether a method argument is a collection or a single value: SObject[] query(SObjectType sobType, String field, Object data) { // Want ...
Keith C's user avatar
  • 134k
10 votes
2 answers

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
5 votes
2 answers

Map<Object, List<SObject>> cannot be cast to Map<String, List<Account>>

I'm trying to cast a Map<Object, List<SObject>> to Map<String, List<Account>>, which fails with the error Incompatible types since an instance of Map<Object,SObject> ...
ipavlic's user avatar
  • 3,684
2 votes
3 answers

Why can Map<Id,List<SObject>> be assigned to Map<Id,List<Account>>?

Assigning a sobject map to a specific sobject-type is not possible, i.e Map<Id,SObject> sobjectById = new Map<Id,SObject>(); sobjectById.put(a.Id,a); Map<Id,Account> accountById = (...
Pablo Gonzalez's user avatar
2 votes
3 answers

casting a map of Id, SObject to a map of Id, customObject

Map<Id, Segment__c> noLockedRecordsMap = (Map<Id, Segment__c>)new LockedRecordHandler().removeLockedRecords(newMap); The above compiles fine. Get this error at runtime: Invalid ...
mackmama's user avatar
  • 659
0 votes
2 answers

What's the best way to initialize a list of strings in Apex?

I have a Map<String, Object> idCollection. Object accountIdObject = idCollection.get('accountId'); Doing this gets me a single string value. Now I am sure that accountIdObject is a String and ...
Knight of the Vale's user avatar
6 votes
2 answers

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
3 votes
1 answer

Illegal assignment from SObject

In Apex, I cannot successfully execute this anonymous block without casting on Ln 2 below: List<SObject> lst = new List<SObject>{ new Custom_SObject__c() }; Custom_SObject__c cstom = lst[...
John Mutuma's user avatar
0 votes
1 answer

Enable Map type to hold Integer, String, Boolean, Map, List... objects? (But not generic Object)

I'm attempting deserialize a list of a custom object in Apex, but got an error: FATAL_ERROR System.JSONException: Apex Type unsupported in JSON: Object This is because my ContactPostBack class ...
Ian's user avatar
  • 9
-1 votes
1 answer

Can I Convert Map<String,sobject> to Map<String,object> [closed]

I have Data in MAP<String,sobject> type map and I wants to put it in Map<String,object> type Map. Please help with this casting.
developer's user avatar
-2 votes
1 answer

Is there a way I can run an asynchronous batch class synchronously? [closed]

I know, it should not be done. But theoretically is it possible?
Gargi Gupta's user avatar
4 votes
2 answers

Cast arrays in Apex

Its been a long time since I casted an array and cant remember if it can be done the way Im hoping. I have an array of type Row (Row[] rows) that is returned from a method. The method I need to pass ...
discodowney's user avatar
0 votes
2 answers

Apex parameterized types

In the Salesforce docs for parameterized types stands the following: Lists, maps and sets are parameterized in Apex: they take any data type Apex supports for them as an argument. That data type must ...
Michael Munta's user avatar
6 votes
1 answer

Unexpected Iterable behavior in Apex

Set implements the Iterable Interface based on the latest Salesforce release (API 58). I tried to refactor my code to make it simpler and use Iterable<Object> as a supertype for a List<Object&...
Piotr Gajek's user avatar
  • 2,422

15 30 50 per page