Skip to main content
1 of 2
Luiggi Mendoza
  • 85.9k
  • 16
  • 160
  • 354

You can ease the code by always retrieving the List value in the for loop, then if it is null create a new one and add it to your Map, otherwise add the value to the list.

for (int i = 0; i < records.length; i++) { List<String> value = sfFundIdsByContact.get(breakdown.getSalesConnect__Contact__c()); if (value == null) { value = new ArrayList<String>(); sfFundIdsByContact.put(breakdown.getSalesConnect__Contact__c(), value); } value.add(breakdown.getId()); } 

As a recommendation, change the definition of

LinkedHashMap<String, ArrayList<String>> sfFundIdsByContact 

to

Map<String, List<String>> sfFundIdsByContact 

Refer to What does it mean to "program to an interface"?

Luiggi Mendoza
  • 85.9k
  • 16
  • 160
  • 354