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
rajesh reddy 3rajesh reddy 3 

Map with in a Map how we can use

HI All ,
Map with in a Map how we can use in Salesforce can any one give the best practices

regards,
rajesh
 
Best Answer chosen by rajesh reddy 3
bob_buzzardbob_buzzard
Best practice is only to use a map containing a map if you really need to - an example might be to have a map keyed by account id that contains a map of contacts keyed by contact id. 

The structure you'd have there is:
Map<Id, Map<Id, Contact>> contactsMapByAccountId=Map<Id, Map<Id, Contact>>();
Code that uses these type of structures can be difficult to understand, especially for new or junior developers.