3

I have an inline visualforce page in which I am showing data from 3 objects using a wrapper class. Now what i want is my 2nd column(record type name) to sort in asc order and 3rd column(roles) in desc order and my 3rd column(roles) value is correspond to 2nd column(record type name)

what i have tried is : by following link : http://www.experts-exchange.com/Programming/Misc/Q_28337339.html

public class ContactRollup implements Comparable
{
    public Contact contactObj { get; set; }
    public String roles { get; set; }
    public String rolesAcc { get; set; }

    public ContactRollup( Contact ct, String role ,String accRole )
    {
        contactObj = ct;
        roles = role;
        rolesAcc = accRole;
    }
    public Integer compareTo(Object compareTo)
    {
        ContactRollup objWrap = (ContactRollup) compareTo;
        if (contactObj.RecordType.Name == objWrap.contactObj.RecordType.Name && roles == objWrap.roles) return 0;
        if (contactObj.RecordType.Name == objWrap.contactObj.RecordType.Name && roles > objWrap.roles) return 1;
        if (contactObj.RecordType.Name == objWrap.contactObj.RecordType.Name && roles < objWrap.roles) return -1;
        if (contactObj.RecordType.Name > objWrap.contactObj.RecordType.Name) return 1;
        return -1;
    }
}

please can anyone help me out from this..? thanks in advance!!!!!!

1 Answer 1

7

Now that you have implemented Comparable, you can use the sort() method on a list of your objects.

list<ContactRollup> ctRollups = new list<ContactRollup>();
//populate the list here

ctRollups.sort(); 
//the list will now be sorted according to your compareTo logic.

Documentation on Comparable Interface: https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_comparable.htm

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .