Tuesday, 3 February 2015

Sort Map in Apex Class


Convert the map in to list, to sort the map in salesforce. Below is the example for that.

public class sortmap{

public void mapsort()

{

      map<Integer,string> sortm = new map<Integer,string>();

      List<Integer> sortlist = new List<Integer>();

      sortm.put(10,'E');

      sortm.put(89,'F');

      sortm.put(1,'T');

      sortm.put(2,'Y');

      sortm.put(90,'R');

      system.debug('----------------'+sortm);

      // To sort this map

      sortlist.addall(sortm.keyset());

      sortlist.sort();

      for(Integer i : sortlist)

      {

                  system.debug('Sorting the Map in salesforce'+sortm.get(i));

       }

}
}

No comments:

Post a Comment