Wednesday, 23 March 2016

10+ ways to delete records in Salesforce

10+ ways to delete records in Salesforce

This blog post will focus on deleting things from Salesforce.


We'll run through all of the ways I can think of that you can delete records, starting with the basic and going through to the more advanced options.

Did I get them all? Let me know if you can think of another way to delete stuff!


Deleting Records

I often joke to customers that there are 3 ways to do everything in Salesforce, when it comes to deleting there are actually many more than that. 

  1. Delete button on the Record

    Deleting a single record in Salesforce is pretty straightforward.

    Just navigate to the record you want to delete and look for the standard Delete button. Clicking this button will move that record into your ORG's Recycle Bin.

    N.B. If you don't see the Delete button you may need to edit the page layout to add it.
    Standard Delete button


  2. Delete from the List view

    When viewing a list of Accounts, Contacts or Leads etc. you will see a 'Del' link against each record. Clicking on this will send the record to the Recycle Bin.
    Delete from list view


  3. Mass Delete Records

    Salesforce has an in-built mass-delete record tool which is available via the Quick Find box. When deleting records you have the ability to control whether the records are permanently deleted or get sent to the Recycle Bin.

    You can delete up to 250 items at one time.

    https://help.salesforce.com/HTViewHelpDoc?id=admin_massdelete.htm

  4. Use Data Loader or other IO Tools
    There are various tools you can use to delete records including Data Loader, Jitterbit, and  Dataloader IO amongst others. These dedicated tools give you a lot of control over inserting, updating, and deleting data in your Org.

    Here is an explanation of this point from the Salesforce online documentation.

    https://help.salesforce.com/apex/HTViewHelpDoc?id=inserting_updating_or_deleting_data.htm&language=en

  5. Apex
    Using Apex you could create a Class or Trigger that deletes records programmatically.

    Want to delete a Lead once a Sales rep puts it into a certain Stage/Category - consider a Trigger with code along the lines of this one described by Andrew Boettcher on his blog.

    More information on this point available here:
    https://developer.salesforce.com/forums/?id=906F00000009357IAA

  6. Truncate Button on Custom Objects
    This is a brand new entry on this list as I hadn't come across the Truncate function before yesterday. Thanks Deepak Anand for his post on the Truncate function.

    The Truncate button, once activated allows you to clear all records from a custom object. A particularly good use case would be if you'd created a lot of test records and just wanted to start afresh whilst preserving all of the object's configuration.

    More information on this function is available from:
    https://help.salesforce.com/HTViewHelpDoc?id=dev_object_trunc.htm&

  7. Delete via URL

    I haven't had a chance to try this one, but Salesforce allows you to create custom buttons and links that call standard functions.

    On this blog post by Evan Walsh he suggests the syntax below for your button/link

    https://[instance].salesforce.com/setup/own/deleteredirect.jsp?delID=[recordID]

  8. Delete a record from a custom Visualforce page

    Using Visualforce you have full control over the look & feel of a page along with the associated buttons and commands.

    This post from Michael Welburn has a nice example of a custom function written in Apex and used on a Visualforce page.

    The actual code for including a Delete button on a VF page is:        

     <apex:commandButton value="Delete" action="{!delete}"/>
    More information available from:

    http://salesforce.stackexchange.com/questions/28586/adding-delete-button-to-vf-page

  9. Using Developer Console
    The Developer Console allows you to enter Apex directly via the Execute Anonymous Window into your Salesforce ORG.

    To delete some records using this method, open up the editor window and enter some code like this - swapping MyObject for the object you want to delete from.

    delete [SELECT Id FROM MyObject];

    Bear in mind that you can only delete 10,000 records at a time using this method. To ensure your code doesn't hit a governor limit amend it to this:

    delete [SELECT Id FROM MyObject LIMIT 10000];
    Developer console allows you to enter Anonymous Apex for deleting records
    More information on this can be found here:
    https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/langCon_apex_dml_examples_delete.htm

  10. There's an App for that

    You can download a variety of App from AppExchange that give you additional functionality around deleting records.

    One example is called Mass Delete from Salesforce Labs which allows you to select multiple records and delete them with one button click.

    Mass Delete
    https://appexchange.salesforce.com/listingDetail?listingId=a0N300000016YuDEAU

  11. Ask someone else to delete the records
    Ok, not strictly a Salesforce function but a friend of mine quite rightly pointed out that this would be an alternative approach so it made it on the list.



    Source: http://www.teamworkandleadership.com/2015/05/leaders-must-delegate-why-is-it-so-hard-3-easy-practical-tips.html
Well, that's the list so far. Did I miss any?

Let me know via the comments section and many thanks for reading.