You need to sign in to do that
Don't have an account?
Visualforce and Map issue.
I'm wondering if anyone else has had this experience or knows why it won't work.
I know Map.values() returns a list of objects in an arbitrary order. However, what I didn't know was that Visualforce can't understand this order.
I had a visualforce page that was showing a list of Accounts and some objects inside of them. For many reasons I was storing the Accounts in a Map grouped by their IDs and stored in a wrapper class.
Map<Id,AccountWrapper> AccountMap;
So in my getAccounts() Method I was just using this at the end:
return AccountMap.values();
But I was getting some very strange behavior when users made changes to the Account Wrapper and saved it.
Turns out sometimes it would save Account 1 data into the Account 2 wrapper object.
I switched the end of the getAccounts method to the following:
AccountWrapper[] AccountList = AccountMap.values(); return AccountList;
Now the AccountList always has the right values.
Does anyone know why maps cannot be sent directly to the page? Why can't Salesforce update map values?
The right way to use maps in VF pages is to use <apex:repeat> to repeat over the keys and get the values. i.e
<pre>
<apex:repeat value="{!accountMap}" var="key">
<apex:outputText value="{!accountMap[key].Account.Name}"/><!--Something like this>
</apex:repeat>
</pre>