Posts

Showing posts from June, 2016

Sorting the list rows via apex Comparable interface

For sorting the existing data we can use ORDER BY clause in SOQL query, however for non existing data we usually create ' map'  then take help from ' for' loop compare from previous values which involves lots of code consequently may bump up the apex cpu time . So to avoid this we can use Comparable interface, where we can pass the list of existing or non existing data in org, for better understanding please refer the below code, you can try in your org as well : 1. Create a global class which implement the comparable interface : -------------------------------------------------------------- global class SortingUser implements Comparable {     public Long id;     public String name;     public String phone;          // Constructor     public SortingUser(Long i, String n, String p) {         id = i;         name = n;         phone = p;     }          // Implement the compareTo() method, mendatory method it returns an Integer value that is the result