Skip to main content
Eric Adams (Horizon Discover) ha fatto una domanda in #Apex

Hi all, I have a question and a followup question.

 

I have a query that potentially pulls multiple records:

 

//Line 25, 26, and 27

List<Territory__c> terrList = [SELECT Name, OwnerId FROM Territory__c WHERE Name IN :allZips];

system.debug('terrList = '+terrList)

After gathing the list, I run a loop to assign the Name and OwnerId to a a Map

// Lines 36,37,38,39,40

system.debug('terrList.size()' +terrList.size());

for(Territory__c t : terrList){

system.debug('for(Territory__c t : terrList) runs');

ziptoId.put(t.Name, t.OwnerId);}

system.debug ('ziptoId.size() = '+ziptoId.size());

It appears that the the code will use the first record in query and assign to the Map.  Is this True?

If this is true, is there a way to assign a random value (of the queried values) to the map instead of first?
1 risposta
  1. 16 mar 2021, 14:06

    Oops- screenshot of the debug log when I enter in a value that triggers more than one record in the query:

     

    Oops- screenshot of the debug log when I enter in a value that triggers more than one record in the query:

0/9000