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
Ramana123Ramana123 

Can anyone help to write the nested map in below code , I am getting error

In the Second If-condition i am confued how to write the code can anyone help me in this how to write the code .

I am getting Account servicing records which are linked to account



public class Account_Related_Account_Servicing {
    List<Account_Servicing__c> Accountservicing_records = new List<Account_Servicing__c>();   
    Map<Id,Map<Id,List<Account_Servicing__c>>> Account_RelatedRecords = new Map<Id,Map<Id,List<Account_Servicing__c>>>();
    Map<Id,List<Account_Servicing__c>> listrecords = new Map<Id,List<Account_Servicing__c>>();
    Public void Account_Linked_Account_Servicing_Records()
        {
              Accountservicing_records = [select Id,Account__r.Id,Name from Account_Servicing__c where Account__c != Null ]; 
            for(Account_Servicing__c abc:Accountservicing_records)
                 {
                     if(listrecords.containsKey(abc.Id) )
                         {
                                 listrecords.get(abc.Id).add(abc);
                         }
                     else
                         {
                                listrecords.put(abc.Id,new List<Account_Servicing__c>{abc}) ;
                        }
                     
                     
         //   In this how to write the code        
                    if(Account_RelatedRecords.containsKey(Account__r.Id) )
                         {
                                 Account_RelatedRecords.get(Account__r.Id).add(abc);
                         }
                    else
                         {
                                Account_RelatedRecords.put(Account__r.Id,Map<Id,List<Account_Servicing__c>>) ;
                        }                     
                    
                     

                           }
            System.debug(Account_RelatedRecords);
            
           
          }    
}
ANUTEJANUTEJ (Salesforce Developers) 
Hi Srikanth,

Can you elaborate on the use case with an example so as to check further and respond back.

Thanks.
Ramana123Ramana123
Hii, I want to get the Account_Servicing records that are linked to Account (Lookup). In my Inner Map i have Account_Servicing Id and its records . And in My main map i want account id and its related records(means Account_Servicing records linked to account)