How To Add Custom Button In List View Of Standard Object In SalesForce

In this post of salesforce tutorial we will see how to add custom button in list view of standard object like lead or contact etc. in salesforce .

To add custom button in list view we need to create button.So we will also see how to create button for salesforce custom object.

In this we are adding a custom object to lead list view.On clicking of that button we will show a visualforce page that will display  Lead records that we selected in list view .If no record is selected in list view then an alert box will popup showing message no record is selected. Here is what we will see List View Button

To create button for custom object in salesforce go Setup in upper right side of your developer account.And then on left side under Build section click on customize and choose the object for which you want to create button as shown below.Here i choose Lead Standard object. Lead Standard Object

  •  Click on New Button or Link  as shown below .

lead list view button

  •  fill entries for label(name that you want to display over button),button name.Description is not mandatory.Then choose display type as list.Change behavior to Execute JavaaScript as shown below. We need to use .js files  in order to use the api of salesforce to connect and fetch the records using SOQL .The below two js files need to add 

    To display selected record we need to get Ids of selected records and then we have to pass these ids to controller so that we can get selected records and able to display on visualforce.The following code does the same.

    From above code we have just passed selected record ids to controller with URL of the visualforce page

List view button

  • After writing the code we need to save .And Again under Build section go to customize and select the object for which you want to add custom button .This time select click on Search Layout link as shown below.

List View Button

  •  Click on Edit button of List View as shown in

List View

  • Add your button in selected section like this
  • List View
  • Now We are done with all customization stuff. you can see this button on List view.But to see selected record on Visualforce page we need to write visualforce page and controller for that page.

Here is controller code.It is very simple to understand. ListViewButton.cls

Here is Visualforce page code . lead_records_page

Now we are done .here is our button on lead List View . List View Button     Now on click we will see selected record on visualforce page . Selected records from list   That all in this post.This was very simple.I will get back very soon with more interesting and usefull post.By then take care and enjoy development.

Related Posts

About the Author: devender kumar

java/j2EE developer

Comments are closed.