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
SFDC ROCKSFDC ROCK 

map and containskey

 if(!TypeAmountMap.containsKey(Shot.type__c)){
                   
                    TypeAmountMap.put(Shot.type__c,Shot.Amount__c);
                    system.debug('TypeAmountMap1'+TypeAmountMap);   // every time I am getting records here
                }else{
                    TypeAmountMap.put(Shot.type__c, TypeAmountMap.get(Shot.type__c)+Shot.Amount__c);
                    system.debug('TypeAmountMap2'+TypeAmountMap);     // records are not getting created any time ....if i am inserting multiple records also. what can be the reason ? why not coming here
                                                                         
                   note: type__c : formula fiel
 TypeAmountMap this map is having value type__c and amount__c which every time getting populated.
Raza0195Raza0195
Map<id,List<Contact>> mapIdVsConatcts = new Map<Id,List<Contact>>();
Set<Id> setOfId = new Set<Id>();
for(Account acct :[SELECT Id,Name FROM Account]){
    setOfId.add(acct.Id);
}
for(Contact con:[SELECT Id,LastName FROM Contact where AccountId IN:setOfId]){
    if(!mapIdVsConatcts.containsKey(con.Id)){
        mapIdVsConatcts.put(con.Id, new List<Contact>());
    }
    mapIdVsConatcts.get(con.Id).add(con);
}
System.debug('mapIdVsConatcts'+mapIdVsConatcts);


Map<id,Account> mapIdVsAccount = new Map<Id,Account>();
Set<Id> setOfId = new Set<Id>();
for(Account acct :[SELECT Id,Name FROM Account]){
   mapIdVsConatcts.put(acct.Id, acct);
}