I am currently trying to pass in checked objects from a salesforce related list from the Accounts Page, via a custom Visual Force List Button in order to instantiate my Apex classes based on the checked objects.

I will be making tables/lists right under the checked objects within the related list based on the Apex class results

Does anyone have an idea how to do this?

  • Are you going to directly modify the related list based on selected items (ie show child records of records in the list)? If so, you need to override the entire page and do quite a bit of direct DOM manipulation. I've done this (creating new related lists based on pseudo relationships), so I can throw some code your way if you want an example. – Caspar Harmer Jul 18 '16 at 20:27
  • Of course, this code won't work if you ever move to lightning UI... – Caspar Harmer Jul 18 '16 at 20:28
  • I don't have to worry about Lightning UI, and yes, I will modify the Related List. For example, you can see a related list of all products of a customer. You check on 2 out of 3 products, then click my custom button, which, under each selected product, displays another list of the products and custom details of those products which will be managed by my apex classes. – Toni Lee Jul 18 '16 at 20:56

To enable a List Button, first define a Visualforce Page whose <apex:page> tag uses the standardController and recordSetVar properties. The former should use the child object on your related list, the latter just gives the list of records a name for you to reference in your markup. You can loop through them using just Visualforce by referencing the selected property on the ApexPages.StandardSetController:

<apex:page standardController="ChildObject__c" recordSetVar="records">
        <apex:pageBlockTable value="{!selected}" var="record">
            <apex:column value="{!record.Name}" />

You can also reference them in Apex if you define an extension and include it using the extensions attribute.

public with sharing class MyListButtonExtension
    public List<SObject> selected { get; private set; }
    public MyListButtonExtension(ApexPages.StandardSetController controller)
        selected = controller.getSelected();

Or you can reference just the Id values selected in a Javascript button using the GETRECORDIDS function.

Whichever of the above you pursue, make sure when creating the List Button itself that you select the Display Checkboxes (for Multi-Record Selection) option.

List Button Configuration

  • That's exactly what I needed! Thanks Adrian. In hindsight, my question was pretty vague, so my bad. One question: won't your VF page have use the MyListButtonExtension class as an extension? – Toni Lee Jul 19 '16 at 3:03
  • The Behavior option must(!) be set to the option in the image("Display in existing window without sidebar or header"). When I tried the other options it failed. BTW, do you by any chance know why? – Randall Flagg Jul 11 '18 at 6:19
  • @RandallFlagg I do not know. That sounds like a good new question to ask. You should of course include more detail so your question is answerable by the broader community. – Adrian Larson Jul 11 '18 at 15:17

I think you should use the GETRECORDIDS function provided by Salesforce for just this sort of thing.

It is used to select ids from any selected items in a list, be they a list view or a related list.

Here's how you would use it:


var selectedRecordIds = {!GETRECORDIDS($ObjectType.YourSObject)};

if (selectedRecordIds.length < 1 ) {
    alert("Please selecte at least one record");
//... and so on 

Look here for more info.

For the modification of the list... it's a bit hard to show you the exact code as it's pretty complicated, uses Angular and doesn't do exactly what you would want it to (I'm using it to generate entirely new lists).

What I'd do in your case is try to get your controller code (perhaps a webservice would actually be best here) to return you a JSON map of records, indexed by the selected ids of the rows that you want data for.

I'd then find each related list row and use the append function to add your new child list to that row. You might have to experiment how best to get these new rows to show up - It might be easiest to completely remove the row and replace it with a new table containing that row + child records as subsequent rows.

Let me know if you'd like more help.

  • Thanks, I think as long as I can get the records that a user checked the box on into my apex class, I'll be ok with experimenting with populating the custom related list. I'll try your code out in my visual force page and let you know! Thank you! – Toni Lee Jul 19 '16 at 3:01

Please correct me if I am wrong, you want to display custom related lists of some selected objects only in an inline vf page under Account.

You can do this, by passing the object names via getter setter in controller, and then rendering the related list tables based on the selected objects.

  • So I'm trying to get the custom related list squeezed between objects in a related list, but the custom related list will be of different numbers of columns from the two object related lists on top/below it. – Toni Lee Jul 19 '16 at 2:56

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.