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
Flight PlanFlight Plan 

Visualforce : "This map cannot be used in an iteration because the keys cannot be sorted"

Hello,

 

I have a scenario to display data in tree structure for that am using approach of map on visudalforce page.

The map structure look like

Map<A,Map<B,List<C>>> mymap = new Map<A,Map<B,List<C>>>();

 

Where A,B,C are wrapper classes in which I have implemented the equal and hashcode method.

 

Am able to generate the map data properly in Apex controlller and when iterating it on VF page it giving the mentioned error.

 

On VF page code look like

<apex:repeat value="{!mymap}" var="m">

     {!m.name}

   <apex:repeat value="{!mymap[m]}" var="p">

                 {!p.name}

     <apex:repeat value="{!mymap[m][p]}" var="q">

                  {!q.Name}

     </apex:repeat>

    </apex:repeat>

    </apex:repeat>

 

Please let me know if I did any thing wrong which causing this error.

Thanks in advance.

 

 

Dhaval PanchalDhaval Panchal
Use wrapper class to display data in tree structure.
Dhaval PanchalDhaval Panchal

Below is the sample wrapper class.

	public List<Main> lstMain{get;set;}//this list you can use to dispaly your data	
	public class Main{
		public A a{get;set;}
		public List<parents> lstParents{get;set;}
	}
	public class parents{
		public B parent{get;set;}
		public List<childs> lstChilds{get;set;}
	}
	public class childs{
		public C child{get;set;}
	}

 Using this you can display data like below

A
	a
		1
		2
		3
	b
		5
		6
		5
	c
B
	a1 
		9
		2
	b1
		11

This is just an idea if it is helpfull to you.