I am pretty new to Apex , so it would be great if anyone can help me debug the error .

This is my map getting initialised

public Map < String,RecordSum.TotalBlock > TotalBlock {set;get;}

Later in the code

TotalBlock = new Map < String,RecordSum.TotalBlock >();

Error message :

Map key - not found in map Error is in expression '{!IF(data.account.Flag__c <>null , TotalBlock[data.account.Type__c+'-'+data.account.Flag__c+'-'+data.account.Line__c].‌​Total,TotalBlock[data.account.Type__c+'-'+data.account. Line__c].Total )}' in component in page ABCD

How do I approach such an error?

  • Please paste your full code in here. – Jarvis Jan 8 '15 at 7:39
  • and also paste the error message please – Novarg Jan 8 '15 at 7:46
  • Error message : Map key - not found in map Error is in expression '{!IF(data.account.Flag__c <>null , TotalBlock[data.account.Type__c+'-'+data.account.Flag__c+'-'+data.account.Line__c].Total,TotalBlock[data.account.Type__c+'-'+data.account. Line__c].Total )}' in component <apex:outputText> in page ABCD – Vanilla_Sky Jan 8 '15 at 8:04

So I am assuming that your VF throws error as Map Key is not found.

The solution is to check the key in Apex Code, and prevent the rendering of the element or component before the attempted access.

Its a fairly common issue with people have already taken shot at it :

can we check if a key exists in a map in vf page


Indeed VisualForce throws an error when a key is not found in the map, so you have to take care of knowing wether the key is there or not.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.