Hi everyone im a beginner in development.

I have a getter method that returns the list of Project__c object records.I want user to select one among that values and i want to do further processing in controller. How can i achieve it ? i am getting error

java.lang.ClassCastException: core.apexpages.el.adapters.SObjectELAdapter cannot be cast to java.lang.Comparable

Vf Page:

 <apex:pageBlockSection columns="3"  rendered="{!showSection}" >
      <apex:pageBlockSectionItem >
        <apex:outputLabel >Select Template</apex:outputLabel>
        <apex:inputText list="{!Templates}"   value="{!templateProject}" />

Controller Side:

public Project__c templateProject{get; set;}

public List<Project__c> getTemplates() {
        List<Project__c> recentprojects = [Select Id, Name From Project__c  Where Template__c = true ];
    return recentProjects;

Tried to reproduce your error, but in my org, code following the same pattern as yours generated "An internal server error has occurred" error for some reason. Same error happened returning a wrapper list that implemented Comparable and toString or returning a SelectOption list.

The documentation suggests that the list attribute can be a list of objects:

The list attribute is specified as either a comma-delimited static string or a Visualforce expression. An expression can resolve to either a comma-delimited string, or a list of objects. List elements can be any data type, as long as that type can be coerced to a string, either as an Apex language feature or via a toString() method.

But the release notes and this blog post example (and the only case I could get to work) use the simple case of a list of strings rather than more complex objects; I wonder if the more complex objects case is fragile or broken. Will be interested to see if another answer offers a working solution.

Other techniques such as select lists and lookup fields are used more often for selection in Visualforce.

  • 1
    yeah i tried with string list earlier and it worked fine too... dont know why istnt working with other objects.. :(( – RAJ KIRAN Jan 22 '17 at 9:46

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.