1

(SFDC Classic)

Given ListView VF page/controller invoked by a ListView button

PAGE

<apex:page id="thePage" standardController="Contact" extensions="ContactsCtrl" 
           recordSetVar="contacts">    
    <apex:pageMessages/>
    <apex:dataTable value="{!selectedContacts}" var="c"/>    
</apex:page>

CONTROLLER

public with sharing class ContactsCtrl {

    ApexPages.StandardSetController ssCtrl;

    public Contact[] selectedContacts {
        get {return (Contact[]) ssCtrl.getSelected();}
    }

    public ContactsCtrl(ApexPages.StandardSetController ssCtrl) {
        this.ssCtrl = ssCtrl;
    }
}

If the ListView first column is an unsortable field, e.g.

  • A Platform-encrypted field (our org; sad)
  • A multi-select picklist field

Then you will get at runtime this ugly VF page error

core.apexpages.exceptions.ApexPagesHandledException: Object type not accessible. Please check permissions and make sure the object is not in development mode: '003q000000w34tTAAQ') ) ) ORDER BY Name ASC LIMIT 10000 ^ ERROR at Row:1:Column:149 field 'Name' can not be sorted in a query call. Original queryString was: 'SELECT CurrencyIsoCode, Id FROM Contact WHERE ( ((OwnerId = '00536000004Ui8M')) AND (id IN ('003q000000w34spAAA','003q000000w34tTAAQ') ) ) ORDER BY Name ASC LIMIT 10000'

If the first column of the ListView is a sortable field, the page displays fine.

So, how to protect against this as you have no control over the ordering of ListView columns?

Option 1 - try and catch the exception. No go, exception is uncatchable

Option 2 - Get the selected Ids into the controller

(and then do your own SOQL orderBy) without doing a getSelected() method. I can't see any way to do this

Option 3 Convert ListView button to Javascript with Ajax Toolkit

Aside from not being future-proofed for Lightning, does {!GETRECORDIDS} end up under the covers doing a SOQL call with OrderBy that will throw the same issue above? Since being on VF is old enough, going back to Ajax Toolkit is ... enough said.

Option 4 - Tell users not to create ListViews with unsortable fields as column 1

...Hardly scalable

Reference:

Known Issue NO FIX item

Platform Encryption Deterministic Considerations

Your Answer

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

Browse other questions tagged or ask your own question.