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
Nagisetti Satya rameshNagisetti Satya ramesh 

how to create a lighting list buttons in vf page

HarshHarsh (Salesforce Developers) 
Hi,

Please follow the below code and steps to create list buttons in VF Page
  • Create a visualforce page with a standard controller, extension(if needed), and recordsetvar.
  • Create a list view button
  • Add the list view button to Listview layout by going to the Search Layout setting.
VF Page
 
standardController="Opportunity" recordSetVar="opportunities" extensions="ListViewButtonDemo">
    <apex:form >
        <html>
            <head>
            </head>
            <body>
                <apex:pageMessages />
                <table>
                    <tr>
                        <th>Name</th>
                    </tr>
                    <apex:repeat value="{!opportunities}" var="o">
                        <tr>
                            <td>
                                <apex:inputField value="{!o.Name}"/>
                            </td>
                        </tr>
                    </apex:repeat> 
                </table>
            </body>
            
            <apex:commandButton value="Save Changes" action="{!save}"/>
        </html>
    </apex:form>
</apex:page>

Controller: ListViewButtonDemo 
 
public class ListViewButtonDemo {
    public List<Opportunity> opportunities{get;private set;}
    public ListViewButtonDemo(ApexPages.StandardSetController stdSetController){
        // Returns all selected records
        opportunities = (List<Opportunity>) stdSetController.getSelected();
    }
    
    public PageReference save(){
        // Some fancy stuff here.
        try{
         update opportunities;
        } catch(Exception e){
            System.debug('Exception: ' + e);
        }
        return null;
    }
}

Create a Listview Button

1. Go to Setup
2. Opportunities
3. Buttons, Links, and Actions.
4. New Button or Link.
5. Enter the name for the button.
6. Select the display type as List Button
7. Select Content Source = Visualforce Page
8. Select your VF page from the Content drop-down.

Add the button on the Listview Layout

1. Go to Setup
2. Opportunities
3. Search Layouts
4. Edit Opportunities List View
5. Select the button from Available Buttons
6. Click Save. 


Please mark it as Best Answer if the above information was helpful.

Thanks.