2

When I choose my Visualforce Page appended to a Custom Button, I find that I cannot choose pages which use a custom controller at all, and sometimes just some of the pages which use the standard controller.

1
  • based on same SObject
    – C.William
    Commented Oct 20, 2016 at 14:32

2 Answers 2

2

For a Detail Button, you must implement StandardController, and for a List Button, you must implement StandardSetController.

Detail Button

<apex:page StandardController="MyObject__c">

List Button

<apex:page StandardController="MyObject__c" recordSetVar="records">

If you want to include any extensions, they must define a constructor that accepts the relevant controller.

Detail Button

public MyExtension(ApexPages.StandardController controller)
{
    // constructor logic
}

List Button

public MyExtension(ApexPages.StandardSetController controller)
{
    // constructor logic
}
1

This is how Visualforce actions, buttons and links are designed to work. Pages that use standardController (and optionally recordSetVar) are intended to be used against a specific record or set of records from a given object type. You'll find tons of examples and explanations in the documentation, including Mass-Updating Records with a Custom List Controller, Overriding Tabs Using a Standard List Controller, Adding Custom List Buttons using Standard List Controllers, and other places as well. They allow you to define new actions for an object's home page, a button or link on a detail page, or a button on a related list or list view that contains that specific object type.

You must log in to answer this question.

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