2

I understand how to enable the checkboxes on related list items; what I'm unclear of is how to determine in an Apex controller which items were checked. Inspecting the HTTP request made to the Apex page upon clicking the associated button on the related list shows that the IDs of selected items are sent in the POST parameter ids (repeated once for each ID), but I don't know how to use those IDs in the controller: PageReference.getParameters() only yields one ID.

I tried modifying my constructor to accept a StandardSetController, but the list returned by StandardSetController.getSelected() is empty. Am I doing something tragically wrong here?

1
  • Can you post the page, and controllers source? That would help greatly. Commented Dec 22, 2014 at 20:22

1 Answer 1

1

You are certainly on the right track, you should most certainly be able to get the selected items via the standard set controller as follows:

 public MyCtrl(ApexPages.StandardSetController ssc) {
        List<Related_Object__c> selectedRecords = (List<Related_Object__c>)ssc.getSelected();
 }

And your Visualforce page tag should like something like this:

<apex:page standardcontroller="Parent_Object__c" extensions="MyCtrl" recordsetvar="relatedObject">

Where Related_Object__c should be the type of records that you are selecting, and Parent_Object__c is the parent (the detail page that has the related list).

It is important that your list button is set Content Source = Visualforce page, and then select your Visualforce page. If set to a URL or on-click Javascript then this wouldn't work.

You must log in to answer this question.

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