---
schema_version: "1"
id: b4961500da92174de45c81b7797092fe46766729b84c35bb333f1376a8997909
title: "Custom Button Example: Mass Delete"
collection: admin
version: current
locale: en-us
portal_url: https://docs.salesforce.com/admin/current/en-us/platform/264-0-0/links_useful_custom_buttons_mass_delete.md
canonical_url: https://help.salesforce.com/s/articleView?id=platform.links_useful_custom_buttons_mass_delete.htm&release=264.0.0&type=5
source_site: help.salesforce.com
content_type: documentation
content_hash: 367cf62134da3888b4652ddb01c8601e10227fd38ae6efb720f18d3a418a5aa6
description: This example creates a JavaScript custom button for Salesforce Classic that can be added to activity-related lists and list views and allows users to delete selected records at the same time.
products:
  - Salesforce Platform
  - Security
release: "264"
---
# Custom Button Example: Mass Delete

This example creates a JavaScript custom button for Salesforce Classic that can be added to activity-related lists and list views and allows users to delete selected records at the same time.

### Required Editions

<table class="slds-table slds-table_bordered slds-max-medium-table_stacked slds-m-bottom_small edition">
        <colgroup>
          <col>
        </colgroup>
        <tbody>
          <tr class="">
            <td class="slds-cell-wrap" style="vertical-align:top;">Available in: Salesforce Classic</td>

          </tr>
          <tr class="">
            <td class="slds-cell-wrap" style="vertical-align:top;">
              <p>Custom buttons and links are available in: <strong>All</strong> Editions</p>
              <p style="margin-bottom:0;">Visualforce
                pages and s-controls are available in: <strong>Contact Manager</strong>, <strong>Group</strong>,
                <strong>Professional</strong>, <strong>Enterprise</strong>, <strong>Performance</strong>, <strong>Unlimited</strong>,
                and <strong>Developer</strong> Editions
              </p>
            </td>

          </tr>
        </tbody>
      </table> <table class="slds-table slds-table_bordered slds-max-medium-table_stacked slds-m-bottom_small permission">
        <colgroup>
          <col style="width:50%">
          <col style="width:50%">
        </colgroup>
        <thead class="slds-text-title_caps ">
          <tr class="">
            <th scope="colgroup" class="slds-cell-wrap" colspan="2" style="vertical-align:top;" id="d95968e87">User Permissions
              Needed</th>
          </tr>
        </thead>
        <tbody>
          <tr class="">
            <td data-label="User Permissions Needed" class="slds-cell-wrap" style="vertical-align:top;" headers="d95968e87 ">To create or change custom buttons or links:</td>

            <td class="slds-cell-wrap" style="vertical-align:top;" headers="d95968e87 ">Customize Application</td>

          </tr>
        </tbody>
      </table>

![Note](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-platform-extend_click-264-0-0-production-enus/5f7d9219-b7b1-4552-8891-f1aba9b289fc/images/icon_note.png)

Note

JavaScript custom buttons are supported in all editions, in Salesforce Classic only. The mass delete function described here doesn’t work in editions where the API isn’t enabled.

1. Define a button for cases with these attributes. <table class="slds-table slds-table_bordered slds-max-medium-table_stacked slds-m-bottom_small ">
          <tbody><tr class="">
            <th style="vertical-align:top;" headers="d95968e120-option" id="d95968e124">Display Type</th>

            <td style="vertical-align:top;" headers="d95968e120-desc d95968e124">List Button<p>Select <strong class="uicontrol">Display Checkboxes (for Multi-Record
                  Selection)</strong> so users can select multiple records in
                the list before clicking the button.</p>
            </td>

          </tr>
          <tr class="">
            <th style="vertical-align:top;" headers="d95968e120-option" id="d95968e138">Behavior</th>

            <td style="vertical-align:top;" headers="d95968e120-desc d95968e138">Execute JavaScript</td>

          </tr>
          <tr class="">
            <th style="vertical-align:top;" headers="d95968e120-option" id="d95968e147">Content Source</th>

            <td style="vertical-align:top;" headers="d95968e120-desc d95968e147">OnClick JavaScript</td>

          </tr>
        </tbody></table>
    
    Use this sample code:
    
    ```javascript
    {!REQUIRESCRIPT("/soap/ajax/9.0/connection.js")} 
    
    var records = {!GETRECORDIDS( $ObjectType.Event )}; 
    var taskRecords = {!GETRECORDIDS( $ObjectType.Task)}; 
    records = records.concat(taskRecords); 
    
    
    if (records[0] == null) { 
    alert("Please select at least one record.") } 
    else { 
    
    var errors = []; 
    var result = sforce.connection.deleteIds(records); 
    if (result && result.length){ 
    var numFailed = 0; 
    var numSucceeded = 0; 
    for (var i = 0; i < result.length; i++){ 
    var res = result[i]; 
    if (res && res.success == 'true'){ 
    numSucceeded++; 
    } else { 
    var es = res.getArray("errors"); 
    if (es.length > 0) { 
    errors.push(es[0].message); 
    } 
    numFailed++; 
    } 
    } 
    if (numFailed > 0){ 
    alert("Failed: " + numFailed + "\nSucceeded: " + numSucceeded + " \n Due to: " + errors.join("\n")); 
    } else { 
    alert("Number of records deleted: " + numSucceeded); 
    } 
    } 
    window.location.reload(); 
    }
    ```
2. Add the button to your activity list views.
3. Add the button to any page layout that contains an activity-related list. The button deletes any selected task or event in the list.

You can install custom buttons from the Mass Delete app at [https://appexchange.salesforce.com/](https://appexchange.salesforce.com/).

#### See Also

- [Custom Button and Link Samples](https://help.salesforce.com/s/articleView?id=platform.links_useful_custom_buttons.htm&release=264.0.0&type=5 "Use samples of custom Salesforce buttons and links to determine whether they can work for you.")