function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
jadentjadent 

Map Creation of SObject at runtime

I would like to create a map of SObjects but i will not know which SObject until runtime, so the data type declartion would be Map<Id, SObject>. But since only concrete maps are allowed i cannot create a Map (new Map<Id, SObject>. Is there a way to dynamically create a map of SObjects? 

 

For example here is a workaround for Lists.

 

 

List<SObject> myList;myList = (List<SObject>)[SELECT Id, Name FROM Account];

 now myList contains a List of Account sobjects. Is there a similiar workaround for doing this with Maps?