I'm having an issue with the Map Collection. I'm trying to merge some duplicates. I have value that identifies the dupes Number__c
and is appearing on multiple accounts that need to be merged.
I'm trying to create a map that has the Number__c
as the key for the list of Account
records that have that id. However, I end up creating a the same list for ever Key (Number__c
) in the Map.
Output is currently like this.
- Key = 1, List ( Id001, Id002, Id003)
- Key = 2, List ( Id001, Id002, Id003)
- Key = 3, List ( Id001, Id002, Id003)
Here is the code so far. I completed the SOQL query earlier to get All accounts for the loop.
for(integer i=0; i < allAccts.size(); i++){
if (allAccts.get(i).Rating__c == 'Do Not Use' ) {
masterRec = allAccts.get(i);
allAccts.remove(i);
List<Id> dupes = new List<Id>();
for(Account b : allAccts){
if (masterRec.Number__c == b.Number__c && masterRec.Id != b.Id) {
dupes.add(b.Id);
}
mapRaccts.put(masterRec.Number__c, dupes );
masterRec
? Does this code even compile?