Thursday, 14 July 2016

How scared should you be of deleting that Salesforce item?

How scared should you be of deleting that Salesforce item?

The other day I was making some changes to a Salesforce environment and accidentally clicked Delete on a Visualforce page.

"No big deal", I thought, "I'll just recover it from the recycle bin".

Wrong...

Finding out the hard way

It turns out that Visualforce pages (and several other Salesforce record types) do not get sent to the Recycle Bin when you delete them.

This surprised me as it's really easy to delete vf pages (the buttons are right next to each other), and it could contain a lot of code that would take significant time to rewrite or restore from that last backup you remembered to create.

Edit and Delete are close together in the Salesforce UI

So what gets stored in the Recycle Bin?

If you are not already familiar with Salesforce's Recycle Bin, check out the official documentation here.

Essentially though, your deleted items are stored in this location for 15 days before being permanently deleted. You can select single or multiple items to restore back from the Recycle Bin.

However, if it isn't in the Recycle Bin it cannot easily be restored.

What does/does not get stored in the Recycle Bin?

I struggled to find a concise list of items that do/do not get stored in the Recycle Bin.

Luckily, I found this discussion on StackExchange on how to generate a list of safe/not safe to delete items.

  • Open up Developer Console
  • Go to Execute Anonymous
  • Enter this code - (thanks to eyescream for originally posting this snippet)
List<Schema.SObjectType> gd = Schema.getGlobalDescribe().values();

for(Schema.SObjectType t : gd){

    Schema.DescribeSObjectResult D = t.getDescribe();

    if(!d.isUndeletable()){

        System.debug('Item ' + t + ' is not retrievable via Recycle Bin');

    }

    else if (d.isUndeletable()) {

                System.debug('Go ahead - delete ' + t);
    }

}

Using Developer Console to list Undeletable = False items

  • Navigate to your Developer Console Logs and open the most recent one.
Log showing each Object and its Deletion Risk
You can easily filter the log to search for any specific items you want to check.

N.B. One anomaly that I spotted in this log was that Report and Dashboard do not have the isUndeletable flag in the Metadata but they are stored in the Recycle Bin (I tested that again just to make sure).

Recycle Bin view

Will Salesforce improve the Recycle Bin in future?

Salesforce is improving all of the time so I wouldn't be surprised if more safeguards are put in place in future.

After a quick read around, I found this Salesforce Success Idea for adding Visualforce pages and other objects to the recycle bin which you might want to vote for.

Summary

The availability of features like Recycle Bins can make it tempting to delete items quickly, believing that they can be easily restored later if missed.

Salesforce gives a lot of Recycle Bin coverage to declarative elements like Accounts and Reports but if you are creating Apex Classes, Pages, or any of the other object types that don't have Recycle Bin protection - it might be worth a quick pause before clicking delete as I did.

Icon from Iconfinder, artist Capital18