+ Start a Discussion
AndrewXAndrewX 

Why can't I delete an Apex text class file from Force.com IDE?

Not sure if this is the correct discussion board...

 

I wrote a trigger, then I wrote a test class with unit tests.

 

Now I want to rename the trigger file and the test class file. I tried from within the Eclipse IDE selecting 'Refactor/Rename...' but it told me that I can't do that from the IDE, but must do it from Salesforce.com. This isn't true because I can't in fact rename those objects from within Salesforce.com

 

So then I thought I can just delete both the trigger and test file and then recreate them. So I select 'Delete' from within Eclipse and when it asks if I want to delete it from the server too I said yes. But in both cases, (trigger and class file) the delete is failing.

 

Please help anyone.

Best Answer chosen by Admin (Salesforce Developers) 
JonPJonP

Production organizations have stringent rules for deploying Apex code that do not apply to a Developer Edition, 30-day Trial, or Sandbox organizations.  For an Apex code change deployment against production to succeed (including deleting a class), after the change is made you must have 75% code coverage across your entire organization and all test methods must pass.  If deleting a class from a production organization causes your test coverage to dip below 75% or causes one or more tests to fail, the deployment will abort.

 

We strongly recommend against creating Force.com projects in the IDE against production organizations.  Instead, you should create a Development Sandbox and write your Apex classes, triggers, and tests there.  When all is working as you want it, use the Deploy to Server wizard in the IDE to push the changes to your production organization.  All Apex-enabled production organizations include at least one Development Sandbox--see online help for more information.

 

To delete a class using this method, delete the class from your sandbox and then use the Deploy to Server wizard.  In Step 3 you will be given the option to select the class from your production organization, that is no longer in your project, for deletion.

All Answers

jwetzlerjwetzler
Moving this out of the Visualforce forum, this is Apex Code.
JonPJonP
Did you create your Force.com project in the IDE against a production organization, or against a sandbox / Developer Edition organization?
ethanoneethanone
I had a similar issue, so I just copied the code into notepad, deleted the trigger and class then created new ones with the names I wanted then pasted the code back in. Low tech, but effective.
wesnoltewesnolte

Hey

 

You'll probably find that there were other pieces of code relying on the code you tried to delete. If you try the delete from the browser it should tell you what code is dependent on that code. Unfortunately this doesn't happen if you delete from within eclipse.

 

Cheers,

Wes 

AndrewXAndrewX

Hi All,

 

Thanks for your responses.

 

The project was created against a 'Production/Developer Edition' environment.

 

I guess it's possible that there is other code dependent on the trigger and test class, but I can't think what that could be. It's a simple trigger that updates a field on a custom object when the object is created. The test just creates an instance of the object, saves it, and checks that the field was updated.

 

Could it be that the custom object is the object that depends on this trigger? Do I have to delete the custom object before I can delete the trigger?

 

The error I get in the IDE when I try to delete the test class file and the trigger file is:

 

Remote delete failed with the following message. Delete will be aborted. TestMyTrigger: null  package.xml: null

Remote delete failed with the following message. Delete will be aborted. package.xml: null  MyTrigger: null 

 

Thanks for your help.

AndrewXAndrewX
Hi All,

Just want to add that this is all happening in a Production environment
JonPJonP

Production organizations have stringent rules for deploying Apex code that do not apply to a Developer Edition, 30-day Trial, or Sandbox organizations.  For an Apex code change deployment against production to succeed (including deleting a class), after the change is made you must have 75% code coverage across your entire organization and all test methods must pass.  If deleting a class from a production organization causes your test coverage to dip below 75% or causes one or more tests to fail, the deployment will abort.

 

We strongly recommend against creating Force.com projects in the IDE against production organizations.  Instead, you should create a Development Sandbox and write your Apex classes, triggers, and tests there.  When all is working as you want it, use the Deploy to Server wizard in the IDE to push the changes to your production organization.  All Apex-enabled production organizations include at least one Development Sandbox--see online help for more information.

 

To delete a class using this method, delete the class from your sandbox and then use the Deploy to Server wizard.  In Step 3 you will be given the option to select the class from your production organization, that is no longer in your project, for deletion.

This was selected as the best answer
AndrewXAndrewX
Thanks JonP
Walter@AdicioWalter@Adicio
I had the same issue and this resolved my issue. Thanks JonP.