# Maps within Maps

Say I have a map:

``````Map<Lead, Map<Date, Decimal>>
``````

How does Map navigation work in a scenario like this?

I would like to first search the Lead, and then search the Date, in order to ultimately find the Decimal value associated to that Lead.

• How do you know which lead you need to get? What's your key? Id, Email, LastName, combination? Commented Sep 8, 2015 at 2:12
• My key is the Lead's Id. @Bachovski Commented Sep 8, 2015 at 2:13

There are two ways to get to it. If you know the exact keys of both maps you can get straight to it:

``````Decimal myDecimal;
{
}
``````

though this won't work nicely because your key is a lead sObject. Unless you have the same instance of the sObject you won't be able to match the key. I would rather use a lead Id, First Name or whatever combination of keys in order to make this work. So instead of `Map <Lead <Map <Date, Decimal>>` I would create `Map <Id, Map <Date, Decimal>>`. Then it's guaranteed that you'll get the matching value based on the correct Id.

``````Id myLeadId = '00Q100000000ABC';
Date myDate = System.today();

Decimal myDecimal;
{
}
``````

Alternatively, you could iterate through the keys and perform checks for each entry. So in your current scenario you could do the following:

``````Id myLeadId = '00Q100000000ABC'; // This is the Id we're looking for
Date myDate = System.today(); // This is the Date we're looking for
Decimal myDecimal; // we'll store the matching value here (if there is one)

{
{
• Yes this answer is somewhat incomplete without `containsKey`. Commented Sep 8, 2015 at 15:34