function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
SFDC-NOOBSFDC-NOOB 

Why do I get method does not exist or incorrect signature error using comparable interface?

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.  Any help is greatly appreciated.

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(Load.get(comparefield) > 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)
Best Answer chosen by SFDC-NOOB
jp1234jp1234
The problem is that you don't have a get instance method.  Am I correcting in assuming that you want load.get(String arg) to return age if arg is "age,"  companyName if it is "companyName," etc.?

Something like following should work in that case
 
public String get(String arg) {
  if (arg == 'age') {
    return age;
  }
  if (arg == 'companyName') {
    return companyName;
  }
  ... (I'll leave the rest up to you.)
}

 

All Answers

jp1234jp1234
That looks like it has something to do with your parseUtility.load class.  Can you share your code for that class, and also does it have such get instance method?  (The error seems to be from the if statement in compareTo method from the look of it.)
SFDC-NOOBSFDC-NOOB
JP, thanks for your reply.

My application makes a callout, the response is parsed into this class.  Then the list is returned to a visualforce page.

The relevant part of the parse utility class is below.  Thanks in advance!

public class ParseUtility{

public class load   {
        public string age { get; set; }
        public string companyName { get; set; }
        public string origincity { get; set; }
        public string originstate { get; set; }
        public string origindistance { get; set; }
        public string destinationcity { get; set; }
        public string destinationstate { get; set; }
        public string destinationDistance { get; set; }
        public string equipment { get; set; }
        public string length { get; set; }
        public string loadtype { get; set; }
        public string miles { get; set; }
        public string payment { get; set; }
        public string pickupdate { get; set; }
        public string pricePerGall { get; set; }
        public string weight { get; set; }
    }
}
jp1234jp1234
The problem is that you don't have a get instance method.  Am I correcting in assuming that you want load.get(String arg) to return age if arg is "age,"  companyName if it is "companyName," etc.?

Something like following should work in that case
 
public String get(String arg) {
  if (arg == 'age') {
    return age;
  }
  if (arg == 'companyName') {
    return companyName;
  }
  ... (I'll leave the rest up to you.)
}

 
This was selected as the best answer
SFDC-NOOBSFDC-NOOB
JP, great information here!  I am no longer getting the error, my code compiles.  I can toggle sorting; however, it's not in order but that's a whole other issue that I'll figure out.  Thanks for the help.