Changing the way Salesforce Admins and Developers think about client solutions.

Email Alert on Deleted Records – No Code

Delete on Email

This is my contribution to No Code November and a way to demonstrate how you can use Flow to create an email alert each time a record is deleted.  This type of question, especially around record deletion, comes up a lot on the Answers community and if you google it, most of what comes up is Apex-based solutions.

Since Process Builder doesn’t currently support actions on delete we need to be a little bit more creative with this one.

OK, so the 5-line Visualforce page is technically code but you can pretty much copy and paste, you don’t need to learn anything to do it, and you don’t need any test coverage.  So it doesn’t really count.

This is a sort-of follow up post to one I made a few months ago around deleting a record using flow that can be found here.  I’m using Leads again for continuity.

This could be applicable anywhere – from wanting a quick FYI when something happens, to auditing requirements, to slowly giving users more access to their own records while also knowing deep down that they’ll accidentally delete something that they’ll regret later.

What I’m doing in this case is actually replacing the delete button with a flow that will send an email first, and then delete the record.

Update: Thanks to Francis Pindar for pointing out that I had failed to mention that this will only work on changes made through the UI –> clicking the button.  It won’t work on mass deletes, dataloader deletes, Apex deletes, etc.  This was by design, I just forgot to talk about it.  Generally I try to limit my email alerts to cases where they can only be fired through a button click.  Accidentally do a bulk update and send 500 emails to your executives to understand why.  

If you are still getting your feet wet with Flow I recommend going through the Cloud Flow Designer workbook.  I just went through it again the other day and that’s what inspired this post.  74 pages seems like a lot, but it only takes a few hours of your time.

Just like the flow workbook, this post may seem intimidating at first (7 steps is a lot), but give it a shot.  Don’t let the number of steps scare you, I’m just trying to break it down into chunks and doing this as a two-parter doesn’t really make much sense since the first part wouldn’t do anything.

Step 1: Prepare your Flow

You’ll need 3 variables for this which you can add by double-clicking on the Variable link on the resources tab in your flow.


  • varLeadID to store the ID of the Lead you are going to delete.  This will be passed into the flow through the button
  • varLeadFirstName to store the first name of the lead to use in the email
  • varLeadLastName to store the last name of the lead to use in the email


Step 2: Record Lookup element

Drag a Record Lookup element onto the canvas so that you can lookup the first name and last name of the lead you are deleting based on the ID brought in using the button

Here we are using the ID to lookup the Lead record, and then bringing back the name of the lead to store in the other two variables we created


Step 3: Send Email element

This one got me the first time, I was trying to use a pre-existing email alert.  Instead you can use a Static Action:


Once I tried this it was ridiculously easy.  Inside Tip: it’s even easier once you go through the workbook I linked to above.

The template for the body can be created right within the Element, you don’t need to create it outside of the flow.

  • Subject can be whatever you want
  • You need to add a row to pick your email recipients


Step 4: Record Delete element

This hasn’t changed much since my previous post.  You need an ID to delete a record, just like in Dataloader


Once you’ve got the three Elements you can tie them together and you’ve got your flow.  Set the Record Lookup as your starting element


After that you just have to save and activate your flow.  You’ll want to save it as an autolaunched flow because there is no screen element.  Everything runs behind the scenes.  You’ll also want to copy that URL, you’ll use the last bit on the Visualforce page.  If you were creating a URL button you would use the whole thing.  For the page you can also just grab it from the Unique Name field, but the URL is also a great way to test most flows.  I’m just used to pulling it from there.  Don’t worry about my FlynnLightning namespace


Step 5: Visualforce Page

Don’t be scared, this page is really easy.  This is all you have to do:

You have here:

  • a standardController telling it that this is running on the Lead object
    • This will also pass in the Lead ID
  • a flow:interview telling the page what to do
    • In this case launching the flow
  • a finish location
    • {!URLFOR(‘/00Q’)} is telling the page to return you to the Lead homepage

That’s it, that’s your visualforce page.  The reason you need the page is because of Step 6.  At this point you could launch this flow a few ways

  • A custom URL Hack button (which isn’t supported in Lightning)
  • A custom page button that will launch the Visualforce page
  • A quick action that will launch the Visualforce page

However none of those will capture deleting the lead from the Delete button that can be found on list views, which we would also want to account for.  It’s kind of hard to track deleted records when you only track some of them.  Which is why we want Step 6

Step 6: Replace the Delete button

Some people don’t know about this functionality but you can actually replace the standard delete button with a visualforce page instead.  I’ve used it before with this awesome solution to preventing users from deleting records in lower editions where you can’t change the profile settings.

In our case we are going to replace the delete button with our visualforce page –> which launches the flow for us.

Navigate through:

  • Setup > Customize > Leads > Buttons, Links, and Actions
    • and click Edit next to the Delete button
  • Override the standard Delete button with your Visualforce page.
    • This is why we needed the Standard Controller –> so that we could use it to override the Lead button


At this point you don’t need to worry about creating custom buttons, hiding standard buttons, worrying about list views.  Every time they delete a lead you will be notified.

Step 7: Glory

Give it a go, see what happens.  Delete any lead you want and check your email.

Each time I create another flow I find myself learning something new, and to me that seems to be the way to learn it.  You’ve just got to get in there, make mistakes, try again, and then go back and delete all the Unhandled Fault emails that you ignored coming into your inbox with each failure.  I had to finally set up a rule to auto-file them, they show up a lot.

There are so many ways to extend this process, this is really just meant as a starting point to get people thinking about what they could do.  Not being alerted to deleted records is an issue for a lot of users, so this solves that problem right away, it’s then up to each Admin to extend it as they see fit.  As with anything slightly out of your comfort zone, get the basics working first, and then extend it from there.  Starting too complex and you’ll never get it off the ground.

Share Button


  1. Brilliant post! great idea, but this solution only works if a user clicks the delete button as its a UI only action. Any delete operation happening anywhere else (as a result of Apex code deleting a record, someone deleting via data loader, an AppExchange app etc) won’t send an email… (which actually may be a good thing as you don’t want 1000s of emails being fired off when you go a delete a load of records using data loader).

    BUT I’m sure you can do it. Essentially scrap the Visualforce page and the delete logic in the flow leaving just the flow logic you want. Then rather than create the button & VisualForce page just add a bit of code in the delete trigger. It does mean a couple of lines more of code but not massive, but then supports all delete actions from anywhere on the platform. Hmmm I’m going to see if it works…

    • geoffreyflynn

      November 1, 2015 at 7:22 pm

      Dang it, thanks Francis, I knew I had forgotten to write something in there. The email on UI only was by design, I just forgot to call it out. Updating now

Leave a Reply

Your email address will not be published.


20 − seven =

© 2018 ExploitedDevOrgs

Theme by Anders NorenUp ↑