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
Yogesh BiyaniYogesh Biyani 

detail page button to list view button

I currently have a detail page button which call following VF page 
<apex:page standardController="Contact_Preference__c" extensions="myContactPreferenceControllerExtension" action="{!autoRun}">
    <apex:sectionHeader title="Auto-Running Apex Code"/>
    <apex:outputPanel >
        You tried calling Apex Code from a button.  If you see this page, something went wrong.  You should have 
        been redirected back to the record you clicked the button from.
How can this be converted to a list view button without additional code? i.e. select all the records from the list view and call autorun for each record? 

AnudeepAnudeep (Salesforce Developers) 
Hi Yogesh - You need to add a recordSetVar tag to your Visualforce Page

From this post - A visualforce page can be available for either a page view (that gets passed one ID) or a list view (that gets passed a list of 0 or more records).

Here's what you have, and it works for the page view, and the ID of the individual record is passed as the page's id parameter. This doesn't make sense on the list view, because you'd have a list of many different IDs, so they can't all be the id parameter:
<apex:page standardController="Risk__c">
Here's what you can add to change it to be available on a list, 
<apex:page standardController="Risk__c" recordSetVar="risks">

From Salesforce

The component also has a recordSetVar attribute. We use this attribute to change the standardcontroller so that it accommodates a set of records rather than a single record.

In other words, it will pass a list of records, that's why you can select "Display Checkboxes (for Multi-Record Selection)" when you're configuring the button.
So if you want to use the visualforce page exclusively for the page view button/link or exclusively for the list view button, that's your solution.
Another solution is to use a button with URL as the type, and link to your page, but then you won't get the list of IDs, but you could pass the ID (or another value) from your parent object, Contract__c.

Here's an example of building out a page for a list button from Salesforce

Please mark this answer as Best if the information shared is helpful