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
Upton_XUpton_X 

Which value assigned on Put method with multiple values?

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?

 

Upton_XUpton_X

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

 

User-added image