You need to sign in to do that
Don't have an account?
Creative Querying for Many Records Using Collections
I have a query that i want to run which only returns records whose custom string field value is not within the keyset of a map.
The trick is populating the map with thousands of records.
The problem i'm having is i'm running into heap size limits while trying to populate the map. If i can just populate that map within one instantiation/population line of code, i can avoid the heap size exception.
Example below:
Map<String, Custom_Object__c> myMap = new Map<String, Custom_Object__c>([Select Custom_Field__c From Custom_Object__c Where Custom_Field__c != null limit 50000]);
This will instantiate & populate the map with key value pairs on one line, and i avoid the heap exception. However the key for the map is the id of the records, and the value is the record. What i need as the key is the field 'Custom_Field__c'.
Does anyone know how to accomplish the instantiation/population of a map on a single line of code where the key (or value for that matter) is a specific field value?
What i'm trying to accomlish is using that maps keys or values as a filter for another query for another object.
Thanks for the help in advance.
Map<String, Custom_Object__c> myMap = new Map<String, Custom_Object__c>
for( Custom_Object__c co : [Select Custom_Field__c From Custom_Object__c Where Custom_Field__c != null ])
myMap.put(co.id,co);
This might help. Even you won't have to put limit on records,