0

I am attempting to sort a list based on user clicking columns on visualforce page. Seems like the comparable interface is the best way to do this.

I can sort using static variables but it's messy. I would like to have dynamic variable to compare the list elements; however, I am receiving an error -- "Method does not exist or incorrect signature." Any help is greatly appreciated.

This works but I will need many more if else conditions, one for each column. Plus a check to see what column the user clicked.

if(Load.origincity > Loadtocomp.load.origincity)  
          return SortOrder.equals('asc') ? 1 : 0;  
        else  
          return sortOrder.equals('asc') ? 0 : 1;

This way is much cleaner but it's not working.

if((string)Load.get(comparefield) > (string)Loadtocomp.load.get(comparefield))  
          return SortOrder.equals('asc') ? 1 : 0;  
        else  
          return sortOrder.equals('asc') ? 0 : 1;

This is full comparable interface class (with error)::::

public class loadsort implements Comparable  
    {  
      public parseUtility.load load {get; set;}   

      public loadsort(parseutility.load ld)  
      {  
        load = ld;  
      }  

      public Integer compareTo(Object vLoad)  
      {  
        loadsort LoadToComp = (loadsort )vLoad;  

        if((string)Load.get(comparefield) > (string)Loadtocomp.load.get(comparefield))  
          return SortOrder.equals('asc') ? 1 : 0;  
        else  
          return sortOrder.equals('asc') ? 0 : 1;  
      }  
    }  

This is the error:::::: Method does not exist or incorrect signature: [ParseUtility.load].get(String)

  • ParseUtility must be a class, Load an inner class within ParseUtility and get(String s) a method within Load. However, 'get' may run afoul of reserved words in the compiler – cropredy Jan 9 '15 at 18:20
0

The problem was I didn't have an instance method in my parseutiiity class. I just needed to pass the argument into the method and return a value based on some condition.

   public String get(String arg) {
      if (arg == 'age') {
        return age;
      }
      if (arg == 'companyName') {
        return companyName;
      }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.