You need to sign in to do that
Don't have an account?
sfdcFanBoy
Simple Maps - logic please
Hey All,
I have 3 maps of type <String,Decimal>. And the values are as below
m1 - {x1,a1; x2,a2; x3,a3}
m2 - {x1,b1; x2,b2; x3,b3}
m3 - {x1,c1; x2,c2; x3,c3}
All the strings(keys) in all the maps are same. x1, x2, x3.
I want to make a new map M of type <String,decimal,decimal,decimal> and the values should be
{
x1,a1,b1,c1;
x2,a2,b2,c2;
x3,a3,b3,c3;
}
How to achieve this? any logic please
Hi Manish,
If i am not wrong than you want your map this way
x1 as key and a1,b1,c1 as value
for that you can use youe map like
Map<String,List<Decimal>> mapTest = new Map<String, List<Decimal>>();
Than put values like
mapTest.put(x1, new List<Decimal>{a1,b1,c1});
mapTest.put(x2, new List<Decimal>{a2,b2,c2});
mapTest.put(x3, new List<Decimal>{a3,b3,c3});
Or if you want to populate youe map dynamically than you can go through this like
http://abhithetechknight.blogspot.in/2013/10/logic-for-maps-having-list-at-values.html
Thanks
Hit the Kudos button (star) and Mark as solution if it post helps you
You can declare the map this way:
-Glyn
But I do not want to use List<Decimal> as my list of decimals is fixed. Only 3 decimals. And this Map<String, Decimal, Decimal, Decimal> will be used as input for Visualforce charting.
So, please let me know how to dynamically put those individual maps m1,m2,m3 in the required format.
Thanks much!
I also read the blog that Subash posted. I prefer this method of dynamically populating a map of lists:
Obviously, you have to replace "theMap", "theKey", "theValue" and "valueType" with the appropriate variables and type for your code, but the form is concise and efficient.
-Glyn
A map can only have one value. You can't create a Map<String,Decimal,Decimal,Decimal>.
If you don't want to use a List, you can create an inner class:
Then create your map, and a way for the VF page to access the values of the map:
In your VF page, you could use a pageBlockTable:
Is this closer to what you are trying to do?
-Glyn
Here's the code that uses the original maps, m1, m2 and m3:
Or you could do it more dynamically:
Am I getting warm yet?
-Glyn