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
Enrico devEnrico dev 

Access apex Map in Javascript

I m trying to access a the apex Map named  "resultsMap" with javascript, I would like to get contact last name using contact id.
public class AccessMapJS {
	public Map<ID, Contact> resultsMap{get;set;} 
	public String JsonMap{get;set;} 
	
	public AccessMapJS(){
		resultsMap = new Map<ID, Contact>([SELECT Id, LastName FROM Contact limit 3]);
		JsonMap=JSON.serialize(resultsMap); 
	}
}

VF page:
<apex:page controller="AccessMapJS" >
<script>
// Access here resultsMap: get contact last name using contact id

</script>
  {!resultsMap}
</apex:page>

Do you know hoe to accomplish that ?
Thanks in advantage for any advice.
 
Dushyant SonwarDushyant Sonwar
Hey Enrico,
Try Something Like This {!resultsMap[Contactid].lastname}
See Below link Understand much more about it.
http://www.salesforce.com/us/developer/docs/pages/index_Left.htm#StartTopic=Content/pages_dynamic_vf_maps_lists.htm?SearchType=Stem
Enrico devEnrico dev
Thanks for your help!

{!resultsMap[Contactid].lastname} works with Visual force tags, but it seems not working in javascript
Dushyant SonwarDushyant Sonwar
How did you used the resultMap On the Script?
Can you post your vf page for further understanding?
Enrico devEnrico dev
Following is the solution:
 
var contactMap = JSON.parse('{!JsonMap}');
var lastname = contactMap['003....'].LastName;

 
Dushyant SonwarDushyant Sonwar
Thanks for sharing it buddy. :)
Shahroz BegShahroz Beg
Hi Enrico Dev I didn;t get this one.
Please help me by elaborating it.