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

StandardSetController.getSelected() fails on PersonAccount field filter

I have a controller extension which takes a StandardSetController. I have a list button on the Account list view.

And I am using person accounts. 


One of the fields in my view filter is based on a Contact field. But since it's a PersonAccount it shows up under the Account filters, as it should.


However when I call the getSelected() method in my controller I get the following error:


"core.apexpages.exceptions.ApexPagesHandledException: Object type not accessible. Please check permissions and make sure the object is not in development mode: and (Level__r.Name = 'Intermediate'))) ^ ERROR at Row:2:Column:6 Didn't understand relationship 'Level__r' in field path. If you are attempting to use a custom relationship, be sure to append the '__r' after the custom relationship name. Please reference your WSDL or the describe call for the appropriate names." 


This makes perfect sense as the relationship should be Level__pr and not Level__r. But all this is happening in the getSelected() method which is a Standard method on the StandardSetController, So I have no access in order to properly format the query. This seems like a bug in SFDC to me.


Any suggestions? Preferably from somebody in SFDC tech support?


Here's a snippet of the code


public with sharing class StudentCourseBuilderController {

    private ApexPages.StandardSetController setcontroller;

    public PageReference bulkLoad() {
        List<Account> asts = setController.getSelected(); // FAILING HERE
        if(asts == null || asts.isEmpty())
            return null; //asts = [select id from Account limit 3];
        List<Contact> csts = [select id, accountId, internal_id__c, firstName, lastName, 
                    (select course_id__c from Course_Details__r order by course_id__c desc limit 1)
                    from Contact where accountId in :asts];



The reason you are getting the error is that setCon.getselected() returns a collection of SObjects and not a collection of accounts.. try like this


 List<Account> asts = (list<account>)setController.getSelected(); // FAILING HERE


Kiran, Thank you for your response and I made the change.


However that was not the problem. The problem is that getSelected() has not been configured to work with Person Account Contact fields. The relationship needs to be suffixed with a __pr not __r as in Level__pr not Level__r. It fails because it can't find Level__r which doesn't exist.