[SalesForce] The standard list controller and Custom Buttons on Related Lists

When creating a cutrom button on a related list (say the functionality is create a new task), why does my VF/Apex need to make use of the standard list controller (standardcontroller with the recordSetVar attribute defined on your page)? Why not just the standard controller, since in this case, I'm not acting on/displaying a set of records?

Best Answer

I completely agree. If you're not acting on a specific set of record in the related list with your custom button, i.e. if you're building a custom New button, there really isn't any need for a standard set controller. IMHO, salesforce should just have a standard way of passing over the details to a custom button and leave the visualforce page developer to figure out whether to implement with a custom controller, standard controller, or standard set controller depending on their specific requirements.

So why is it needed? I can only guess, but I would assume it's to prevent administrators from accidentally wiring up a button to a visualforce page that may not be able to accept your input.

That said, there are two ways to work around this. First, use a url for the source of your button. Using your example of a new task button on say an account record you could do

/apex/myCustomNewTaskPage?id={!Account.id}

Second, you can create the page and set the recordset var, create the button, then just edit your page. Once the button has been set up it doesn't enforce maintaining the recordsetvar attribute (although it may complain if you try and edit the button later).

Related Topic