0

I'm attempting to build a page that displays a mixed list of Leads and (Person)Accounts sorted by a custom field. I'm able to get the records returned and sorted using the Comparable interface but when I try to display the results in a dataTable, I get an Unknown property error CallList.contactability_rating when I attempt to compile.

What causes this error and how can I resolve it?

The page is very simple:

<apex:dataTable value="{!CallList}" var="item">

        <apex:column >
            <apex:facet name="header">Rating</apex:facet>
            <apex:outputText value="{!item.contactability_rating}"/>
        </apex:column>

</apex:dataTable>

The Controller is also simple:

public without sharing class CallListController {

    public List<CallList> getCallList(){
        List<CallList> itemList = new List<CallList>();
        for(Lead ld : [Select ID, Phone, Contactability_Rating__c, LastName from Lead]){
            itemList.add(new CallList(ld));
        }
        for(Account acct : [Select ID, Phone, Contactability_Rating__c, LastName from Account]){
            itemList.add(new CallList(acct));
        }
        itemList.sort();
        System.debug(itemList);
        return itemList;
    }
}

And the Comparable Interface works when tested in a unit test:

global class CallList implements Comparable {
    global Id id;
    global String phone;
    global String lastname;
    global Integer contactability_rating;

    public CallList(Lead ld) {
        this.contactability_rating = integer.valueof(ld.Contactability_Rating__c);
        this.id = ld.id;
        this.lastname = ld.LastName;
        this.phone = ld.Phone;  
    }

    public CallList(Account acct){
        this.contactability_rating = integer.valueof(acct.Contactability_Rating__c);
        this.id = acct.id;
        this.lastname = acct.LastName;
        this.phone = acct.Phone;
    }

    global Integer compareTo(Object compareTo) {
        // Cast argument to sObjectWrapper
        CallList compareToitem = (CallList)compareTo;

        if (contactability_rating == compareToitem.contactability_rating) return 0;
        if (contactability_rating > compareToitem.contactability_rating) return 1;
        return -1;  
    }
}

The debug in CallListController returns the following list of data:

15:54:10:072 USER_DEBUG [12]|DEBUG|(CallList:[contactability_rating=0, id=00Q29000004MPhhEAG, lastname=Lead 00, phone=212-555-0200], CallList:[contactability_rating=2, id=0012900000ECvNBAA1, lastname=Student 02, phone=2125550102], CallList:[contactability_rating=2, id=0012900000ECvMrAAL, lastname=Student 02, phone=2125550102], CallList:[contactability_rating=3, id=00Q29000004MPhmEAG, lastname=Lead 03, phone=212-555-0203], CallList:[contactability_rating=4, id=0012900000E5wjaAAB, lastname=Student 01, phone=(212) 555-0101], CallList:[contactability_rating=5, id=00Q29000004LsNfEAK, lastname=Lead 05, phone=(212) 555-0205], CallList:[contactability_rating=9, id=0012900000ECvNkAAL, lastname=Student 09, phone=2125550109])

1 Answer 1

0

You need a getter. See also: Apex Properties.

Instead of:

global Integer contactability_rating;

Use:

global Integer contactability_rating { get; private set; }

Or better yet stick with the public access modifier over global unless you have a good reason to use the latter.

You must log in to answer this question.

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