You need to sign in to do that
Don't have an account?
ASHISH KUMAR YADAV 7
how to get duplicate value in map and get unique vale and some
DuplicateMKT hold duplicate value like [65,65,5,5] i need to take the unique value and sum that value and put in map-outletIdByTotalmarket thisis map<sting,string> what is the good solution use map or set and do the calculation anyone can help. //Code Started from here Decimal totalmarket=0.0; Decimal mkttotal=0.0; List<String> DuplicateMKT =new List<String>(); List<String> noDupes; for(String outletmktId : lstStagingByOutletId.keySet()){ List<SNR_Staging__c> currlist = lstStagingByOutletId.get(outletmktId); for(SNR_Staging__c currrecords : currlist){ if(!String.isEmpty(currrecords.SNR_HCV_MARKET_R6M__c) ){ DuplicateMKT.add(currrecords.SNR_HCV_MARKET_R6M__c); System.debug('DuplicateMKT-->'+DuplicateMKT); noDupes = new List<String>(new Set<String>(DuplicateMKT)); System.debug('noDupes-->'+noDupes); } } for(String s: noDupes){ totalmarket = totalmarket + Decimal.valueOf(s); System.debug('totalmarket--->'+totalmarket); mkttotal += Decimal.valueOf(s); System.debug('mkttotal--->'+mkttotal); } outletIdByTotalmarket.put(outletmktId,mkttotal); System.debug('outletIdByTotalmarket-->'+outletIdByTotalmarket); } //code end here
Here's an updated version of the code using a Set and a Map:
If you find this answer helpful,Please mark it as the best answer,