I have recently spent a couple of months developing on the Force.com platform. In this article I will share some of the joys, frustrations and very useful tricks and workarounds I have come across along the way. They have all taken quite a bit of research, pain and perseverance to discover. It is my hope that other people experiencing similar problems will not have to search as far for the solution!
Restoring a previously-deleted Apex class
I found myself in this situation after I deleted an Apex class in a developer environment while using the Force.com IDE (Eclipse Force.com plugin), then later attempted to re-create that class. I recreated the Apex class using the Force.com IDE and attempted to deploy it to my Salesforce environment, which failed with an error:
“entity is deleted”
This error occurs because Salesforce still has a record of that class having existed. The same error occurs if you try to recreate the class using your Salesforce environment’s browser interface. I sneakily solved the problem using another function of the Force.com IDE.
“entity is deleted”
This error occurs because Salesforce still has a record of that class having existed. The same error occurs if you try to recreate the class using your Salesforce environment’s browser interface. I sneakily solved the problem using another function of the Force.com IDE.
Error message:
In the Force.com IDE the error message when attempting to recreate the class was:
“entity is deleted”.
Creating the class using the browser interface gives you a bit more information, warning you that:
“a class with the same name already exists or has previously existed”.
In the Force.com IDE the error message when attempting to recreate the class was:
“entity is deleted”.
Creating the class using the browser interface gives you a bit more information, warning you that:
“a class with the same name already exists or has previously existed”.
Solution:
- Make sure the Force.com perspective in Eclipse is active
- Open the 'Execute Anonymous' window
- Make sure that ‘Active Project’ is set to a project in your workspace which is setup to receive its data from the environment that you wish to restore the class to.
- Enter the following Apex code (or something to its effect), replacing Foo with the name of the class that you want to restore:
ApexClass deletedClass = [SELECT id FROM ApexClass WHERE name = 'Foo'][0];
System.Debug(deletedClass.id);
- Execute the code 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, for example: https://na12.salesforce.com/<paste id here>
- Navigate to this URL, where you can Edit and Save the class.
Robin Smith
Software Developer, Cloudreach

No comments:
Post a Comment