I accidentally deleted a wrong class via the Force IDE and want to restore / undelete it. I found no way to do this....

6 Answers 6


There is an option to Restore from Local History in Eclipse. You could give that a go.

  • 1
    I knew I can do that, but I thought Salesforce.com would also track it and allow me to restore it. At least for managed classes this is possible via Package > View Deleted Components Commented Oct 18, 2013 at 11:15
  • No afraid not. The best you can get is "View Setup Audit Trail" which shows who done what in the admin area. It would be nice if deleted components ended up in the Recycle Bin. As Pavel mentioned, look into using version control.
    – BarCotter
    Commented Oct 18, 2013 at 12:41
  • You can't undelete "View Deleted Components." They are historical in nature. Interestingly, ApexClass, the representative of a class, doesn't have a IsDeleted member, which would be required to find deleted classes through a query.
    – sfdcfox
    Commented Oct 18, 2013 at 15:00
  • BUt I did try using getdeletedrecords, and my recently deleted class was in the result set - but you can't undelete on ApexClass apparently Commented Oct 18, 2013 at 18:35

As BarCotter mentioned you can do it via Local History. Also you can retrieve it back by updating class directory from server (in case this class was saved on server). Also you need to use a version control like git or svn, if you don't - this is very significant thing in software development.


Any chance the class still exists in some other Sandbox ? Or even in Production if you deleted from Sandbox...


This isn't directly an answer, but whenever something like this happens it's a great time to start looking at source control. While I've always felt that Salesforce should be versioning these things for us, that doesn't appear to be likely anytime in the near future.

A simple solution we've used is just to do a daily checkout of all of our apex code and push it to a repo. It lacks much insight into why those changes were made, but does save us from accidental deletions and other common mishaps.

For a more full-fledged solution, take a look at StratoSource RedHat's internal Salesforce project management tool which includes auto-repos and other powerful goodness to manage your internal Salesforce projects.


I did get this technique (Bascially, querying for the deleted class in Dev Console, and then using the Id to display class which seems to work even when class was deleted) to work for me once, but trying it in a dev org now didn't seem to work - but wanted to throw it out in there in case


They way I do it is to use the execute anonymous function from the Developer Console and run the following:

system.debug([SELECT Id FROM ApexClass WHERE Name = 'NAME' all rows]);

Then open the class via https://instance.salesforce.com/Id click edit then save and voila the class is back.



You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .