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
JeremyKraybillJeremyKraybill 

Error processing records from a personalized view

I have a set of views which operate on the child (detail) object of a master-detail relationship. This object is called "Service Booking". One of these views which will be used by most of our users uses the "My Service Bookings" option in the view to only show the user bookings that belong to them. I assume since OwnerId only exists on master objects, not child objects, that this causes the view to look at the OwnerId of the parent.

On the list screen, I have a custom button backed by a VisualForce controller. This controller has a StandardSetController constructor, and uses the getSelected() call on the parent StandardSetController to determine which records the user has checked the checkboxes for in the list view.

The controller works 100% fine if the records I select in the list view come from a view that does NOT use the "My Service Bookings" option in the view. However, if I first view the records in a personalized "My Service Bookings" view, then check off one or more records and click the custom button, I get the following error in a normal exception screen:

FROM Service_Booking__c WHERE ((OwnerId = '005R0000000ECDR') AND ^ ERROR at Row:1:Column:43 No such column 'OwnerId' on entity 'Service_Booking__c'. If you are attempting to use a custom field, be sure to append the '__c' after the custom field name. Please reference your WSDL or the describe call for the appropriate names.

This error is thrown by (I believe) the StandardSetController, and (I am certain) occurs before the constructor of my controller is touched. I verified this by throwing an Exception in the first line of the constructor and the exception was never thrown, I still got the above error. This is confirmed by the system debug logs, which indicate that no custom code was executed.

Is this a known issue with StandardSetControllers when operating on the child/detail objects in a master-detail relationship? Or is there some other controller I can use?

The only workaround I can think of is to have a field on the child object which either looks up or gets copied the OwnerId of the parent, and then use that field in the view instead of the "My <object name>" radio button.

Any ideas much appreciated!
JeremyKraybillJeremyKraybill
So, I found a workaround, which is that instead of using the "My records" radio button on the edit list view, I use the solution described here to create a computed field on the object in question which returns "1" if the current user is the owner, and "0" otherwise, and then explicitly use that field as the filter criteria. Not ideal but it works.

If anyone can shed light on the issue with the StandardSetController I would much appreciate it. I suspect it is a bug in the code that the standard set controllers use, since it appears to only apply to children in master-detail relationships.