+ Start a Discussion
JoeZaloom.ax395JoeZaloom.ax395 

How can I restore a deleted class?

Hello,

 

I had a test class "TestRecordTypes" that is part of a managed package. I deleted the class because I wanted to move the test methods inside the controller that was being tested. This didn't work like I thought it would, so I wanted to restore the code from the deleted class, which I had saved locally.

 

There seems to be no way to overwrite or undelete the class. In Eclipse if I create a new class w/ the same nameI get prompted w/ "Duplicate Component Found," and it asks me if I want to overwrite the remote instance. If I choose "OK" I get a local class w/ the deleted code in it. When I save I get errors for the class and it's meta.xml file saying "Save error: Conflict found while preparing to save 'TestRecordTypes.' to server.  Remote instance has been updated since last save or sync.  Use the Synchronize Perspective to resolve the conflict." But the Synchronize with Server tool doesn't let me upload the code to the server. If I try to deploy the newly created class to the server I get an error "Class is deleted". The deleted class still shows up in the SF UI under Develop / Apex Classes but there doesn't appear to be any way to undelete the class.

 

So I appear to be stuck in that Twilight Zone episode where you walk down a street but always end up back where you started. Is this a "feature" or is there a way to restore the class?

 

thanks in advance,

joezaloom

davidpadburydavidpadbury
Did you find any solution to this? I've recently managed to somehow delete a ApexClass and now I am unable to replace it with a previous version.
Mario Di GenioMario Di Genio

Hi, I know this question has been up for a while, this happened to us with a trigger recently and the solution we found is this:

 

In the schema in Eclipse we retrieve from ApexTrigger all triggers (there you will see all active, inactiva and also DELETED triggers). With the id of the trigger, we put it in the browser, for example, https://na7.salesforce.com/<the id> and that's how we were able to navigate to the class in the org. It allowed us to edit it and activate it, and after saving the trigger appeared again listed and even in the managed package that we had.

 

We tried to do all of this editing the meta file of the trigger changing Deleted for Active but it didn't work, but from the org as explained above it worked perfectly.

 

You can do the same with a class.

 

Hope this helps.

 

 

RobinrobRobinrob

My God, thank you very, very much!

 

At first i didn't quite understand your solution, so i will clarify it here (for a class):

 

Open up Force.com IDE in Eclipse

Open the 'Execute Anonymous' window

Enter this code (or something like it), replacing 'DeletedClass' with the name of the class you want to restore:

 

ApexClass deletedClass = [SELECT id FROM ApexClass WHERE name = 'DeletedClass'][0];

System.Debug(deletedClass.id);

 

Run it and find the id of the class in the Debug output in the 'Execute Anonymous' window

Append the id to the base URL of your Salesforce environment in your browser e.g. :

https://na12.salesforce.com/<paste id here>

 

Then you can Edit and Save the class.

 

Hurray!!

Jordan@BracketLabsJordan@BracketLabs

I tried running this and got a a 'list out of bounds' exception?

RobinrobRobinrob

Hmm, that's interesting. I've since found out about Salesforce's 'delete log':

 

http://www.salesforce.com/us/developer/docs/api/Content/polling_for_changes.htm

 

How long before you tried this had you deleted the Class? I think when i did it, it was on the order of a few hours to a day. Could you try again today and let me know what happens? If it's somehow not in the delete log you won't be able to retrieve it unfortunately.

 

This is good info to know though, as i also wrote my solution in a blog post :)

calvin_nrcalvin_nr

Is there a way to restore changes to a file....One of my VF pages was overwritten by mistake. Can I restore it?