For example.....Suppose I'm getting this data from my Apex Class
objlist=[
{Id: 1, Name:"Jake Peralta", Role: "Employee", Birthday: "01/01/1998"},
{Id: 2, Name:"Amy Santiago", Role: "Lawyer", Birthday: "11/03/1988"},
{Id: 3, Name:"Charles Boyle", Role: "Beneficiary", Birthday: "29/12/1993"},
{Id: 4, Name:"Rosa Diaz", Role: "Spouse", Birthday: "01/06/1968"},
{Id: 5, Name:"Gina Linetti", Role: "Dependent", Birthday: "23/07/1997"},
{Id: 6, Name:"Terry Jeffords", Role: "Sibling", Birthday: "21/04/1989"}
];
I want to sort this w.r.t "Role" field such that the order is:
Spouse
Sibling
Dependent
Beneficiary
Employee
Lawyer
Hi, You can try using the Comparable interface to do custom sort on the sObjects List.
Please refer to below links and try to implement the same. https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_list_sorting_sobject.htm
https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_comparable.htm
Thanks & Regards
Mukesh Katoch