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
Newbie__SalesforceNewbie__Salesforce 

Generate Map of Map of List

for(Case caseObj : [SELECT Id,
								   ContactId,
								   AccountId
						    FROM   Case]) {
			if(String.isNotBlank(caseObj.AccountId)){
		    	if(!mapId_Map.containsKey(caseObj.AccountId)) {
					mapId_Map.put(caseObj.AccountId,new Map<Id,List<Case>>());
					mapId_Map.get(caseObj.AccountId).put(caseObj.ContactId,new List<Case>());
					System.debug('Inside If');
		    	}
		    	mapId_Map.get(caseObj.AccountId).get(caseObj.ContactId).add(caseObj);
			}
		}
	System.debug('Map of Map------>>'+mapId_Map);

Getting null pointer exception while adding cases
Priya Sharma 37Priya Sharma 37
Put mapId_Map.get(caseObj.AccountId).get(caseObj.ContactId).add(caseObj); inside inner if

for(Case caseObj : [SELECT Id,
                                   ContactId,
                                   AccountId
                            FROM   Case]) {
            if(String.isNotBlank(caseObj.AccountId)){
                if(!mapId_Map.containsKey(caseObj.AccountId)) {
                    mapId_Map.put(caseObj.AccountId,new Map<Id,List<Case>>());
                    mapId_Map.get(caseObj.AccountId).put(caseObj.ContactId,new List<Case>());
                    mapId_Map.get(caseObj.AccountId).get(caseObj.ContactId).add(caseObj);
                    System.debug('Inside If');
                }
          }        
   }
 System.debug('Map of Map------>>'+mapId_Map);