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.
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 PageController: ListViewButtonDemo
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.