function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
AmulAmul 

Delete Apex class from production

Can anyone suggest, how ca we delete apex class from production.

please provide step-step process to delete it from prod. through Force.com Eclipse.

Best Answer chosen by Admin (Salesforce Developers) 
sales4cesales4ce

As Bob suggested, you should first delete it from your sand box using force.com IDE.

 

Below are the steps:

 

1) From Force.com IDE, select the class that you want to delete (Look for .xml extension )

2) Open that .xml version of your class and change the Status tag to Deleted.

3) Right click and save the file.

4) Now select "SRC" folder and right click--->Select  Force.com---> select Deploy to server

5) Log into your production org and follow the steps.

 

Note: if you have any test class for the class that you are deleting make sure you do the same like above and then select those 2 classes for final deployment.

 

Hope it helps.

 

Sales4ce

 

 

All Answers

bob_buzzardbob_buzzard

You need to delete it from your classes directory on your sandbox and then deploy your classes directory to production.  In the deployment window you should then see the option to delete the classes from the target organization.

sales4cesales4ce

As Bob suggested, you should first delete it from your sand box using force.com IDE.

 

Below are the steps:

 

1) From Force.com IDE, select the class that you want to delete (Look for .xml extension )

2) Open that .xml version of your class and change the Status tag to Deleted.

3) Right click and save the file.

4) Now select "SRC" folder and right click--->Select  Force.com---> select Deploy to server

5) Log into your production org and follow the steps.

 

Note: if you have any test class for the class that you are deleting make sure you do the same like above and then select those 2 classes for final deployment.

 

Hope it helps.

 

Sales4ce

 

 

This was selected as the best answer
JimRaeJimRae

This process doesn't seem to work for me, when I follow the numbered steps, instead of a delete option, I get an update option.

 

Any other suggestions.  This is one of the most difficult tasks in all of Apex development.

bob_buzzardbob_buzzard

I usually delete the class from my sandbox and then deploy the whole of the classes directory.    This picks up the fact that my sandbox has deleted classes compared to production and the classes appear as delete options.  

 

Of course I usually then uncheck every other class, but that's optional depending on if your sandbox is different to production.

AmulAmul

thanks its work for me.

melango@ConsLeaguemelango@ConsLeague

Please visit http://www.consleague.com/blog/?p=25 to know how to do it from Command line using Ant Deploy Process

Starz26Starz26

Another easy way to do it is:

 

1. Use IDE to create a new project and download all classes from production

2. In the class you want to delete, open the metadata item and change the status to deleted.

3. save to server, and boom, gone.

SeniorMoveSeniorMove

@Starz26

 

Sweet!  That works great!  BY FAR the easiest way!

daniela.herreradaniela.herrera

Awesome... Thanks!

salesforce19salesforce19

@Starz26: It worked like a charm. 

Marc C.Marc C.

Sweet! Somebody get this guy (@Starz26) a medal.

 

Naresh Kr OjhaNaresh Kr Ojha

Thanks, it works. 

GregWaxGregWax

This method worked for me.

Justin.WilliamsJustin.Williams
Why doesn't this work for me?  I open the metadata on an inactive trigger.  I change the status from Inactive to Deleted.  I right click on the metadata file, hover over Force.com menue, and select save to server.  When its done I check the sandbox org and its still there.  Then when I click on the open metadata file in Eclipe a message pops up saying, "The File 'Dev Apex/src/triggers/npsToJBara.trigger-meta.xml' has been changed on the file system.  Do you want to replace the editor contents with these changes?"   If I click yes it changes the status back to Inactive in Eclipse, If I click No it just asks me that again the next time i click on the open metadata... what the crap?
Lake Ontario DylanLake Ontario Dylan
@Justin Williams - instead of saving the XML metadata to server, right click the entire project and deploy it.
Shahab KhanShahab Khan
I have selected multiple classes and their test classes and deploy them though IDE the result is that all test classes deleted but main classes are still there in production.
Can any body let me know how i can delete those classes?
Starz26 can you please help me?

Thanks in advance.

Ashley@WCELAshley@WCEL
I think the information on this thread is a bit stale. As far as I can tell, connecting directly to production and changing the status to "Deleted" no longer works reliably and runs the risk of causing test coverage issues on your production environment. Neither can you simply change the XML status to Deleted on your sandbox as instructed here (https://help.salesforce.com/apex/HTViewSolution?id=000006188&language=en_US). The only reliable method I found is to log into your sandbox (refresh it from production first if it's gotten out of sync), delete the classes from Setup->Develop->Classes, which will probably force you to first delete dependencies (i.e buttons, pages, etc). Then go into the Force.com IDE, refresh from the sandbox server, delete the classes from your local workspace, and then deploy the entire "src" directory to production. Now you will be shown the pages and classes to delete when it gathers the deployment payload.

I first tried the shortcut method of connecting directly to production and setting the XML status to Deleted, and it worked on my test classes but refused to delete anything else. Of course this caused every deployment thereafter to fail because I no longer had sufficient test coverage on production. I had to gather all that code from an old sandbox, redeploy it to production, and then go through the proper steps outlined above. And it worked flawlessly.

TL/DR: Don't bother with the shortcut, it will cause more problems than it solves.
Rafa_SRafa_S
If your code coverage is below 75%,  none of the provided solutions will work reliably.
  • I'm experiencing classes refusing to accept delete saving to production server because of missing dependent classes.  
  • Cannot deploy from sandbox, because code coverage is below 75% (Many thanks to my shoddy coders)
  • Eclipse kepler has to be the buggiest most broken  IDE I've ever tried.
It seems I'm either FUBAR or SOL. Take your pick.
Phil HironsPhil Hirons
In the the Eclipse Force.com IDE I right clicked on the class and chose delete. If you preview you get the option to delete from server as well. Worked for me.
Shamsher SinghShamsher Singh
@Amul : There are different ways to delete the class form sfdc instance. The simplest way which worked for me is deleting from Eclipse IDE.
1. Just Right Click the class in IDE which you want to delete.
2. It will ask for a confirmation "Are you sure you want to delete file "classname" ?" Click "Yes".
3. Next confirmation will ask you "The requested operation will only delete the resource locally. Would you also like the resource to be deleted from the server?"
4. Click yes and the class is deleted from SFDC instance.
tonantetonante
I tried that and it only deleted from the Sandbox org but not production. If you wish to delete from production you'll have to update the XML meta fiule setting the Status element to "Inactive" and saving that file. Then this should remove from production.
gail.hallettgail.hallett
I've tried updating the metadata and then deploying to another sandbox so I can test this before I actually do this in Production. When I go to deploy, it prompts me to overwrite the class but also shows no changes. When I check on the server I've deployed to, the class is still there and Active. 
ClaiborneClaiborne
I am experiencing similar problems. These steps finally worked:
  1. Create project from sandbox in IDE.
  2. Delete the class in the sandbox.
  3. Refresh all classes in the IDE from server (sandbox). Status of package is now "Deleted".
  4. Deploy all classes from IDE to server.
  5. Uncheck all classes except the one I want to delete.
  6. Execute deployment - Success - Log shows:
# Deploy Results:

   File Name:    classes/AttachLogTallies.cls
   Full Name:  AttachLogTallies
   Action:  NO ACTION
   Result:  SUCCESS
   Problem: n/a

   File Name:    package.xml
   Full Name:  package.xml
   Action:  UPDATED
   Result:  SUCCESS
   Problem: n/a
But no change in class on production. Sort of like Hotel California, "You can delete any time you want, but it never leaves." 

There really needs to be a better way to delete. Maybe we should have "packages" that can be installed and uninstalled.
Vinod Kumar 92Vinod Kumar 92
Hi Starz26,

I came across your steps, after changing the status from Active to Deleted, I don't have option to Save to server/Deploy to Server for the particular Apex class which is under the installed package. Any help here it would be great.

Thanks in advance.
Vinod kumar
Bill JacarusoBill Jacaruso
I found that you have to make sure that depedencies associated with the Class have to be deleted from Production before you deploy from the IDE. I kept getting failures from the IDE, once I deleted a Tab and VF page that was accessing the Class, I was able to deply and remove using the above steps. An easy way to find the dependencies is, once the Sandbox has been setup, just try to delete the Class from there using the Delete button, SF will tell you the dependencies. Just delete those and the IDE method will alow you to deploiy successfully to Production once you have deleted the depencies there as well.
David Roberts 4David Roberts 4
I thought I wasn't deleting the class. It seems there is a delay in the update to the production org. I left the office feeling very frustrated that, whatever I had tried, the class stubbornly remained. The next morning I found it had gone! Hope this helps someone avoid the frustration that I felt.
Chris Collier 6Chris Collier 6
@Starz26 That worked perfectly for me.  I deleted the classes and associated tests at the same time, and haven't had any issues.  I suspect that not deleting them at the same time may cause problems.
Kristen EarpKristen Earp
I use a Chrome/Firefox plugin called Metaforce to delete classes in production.
Helen Arabanos 8Helen Arabanos 8
Deleting from SB and then loading all classes to prod did not work. No delete option appeared, it just loaded all the other classes again. Any other suggestions on how to delete a class from Prod without using eclipse or some other tool?
 
Sharon WardSharon Ward
@Kristen Earp, please can you provide details on how you did that using Metaforce? 
Paul WorltonPaul Worlton

I was using Eclipse/Force.com to set the "Deleted" flag then would "Deploy" to production. Unfortunately, something went wonky with the plugin recently and I was no longer able to connect (and yes, I verified all of my credentials).  The Force.com deploy process always seemed a little iffy to begin with and I think Salesforce is moving away from Force.com anyway (based on recent webcasts), so...

That prompted me to start looking for a different/better way to delete Apex classes.  One thing I noticed is that Apex classes that don't have any methods don't show up in "Setup -> Apex Classes", so deleting them from there is out (I always comment out the entire class before removing it).

Then I ran across an article on setting up MavensMate with Sublime Text (https://www.mstsolutions.com/blog/content/sublime-text-3-mavensmate-forcecom-development) (VS Code will also work).  After getting that all set up, I am now able to set the "Deleted" flag on the metadata file and just save it, which automatically deploys the change to production.  There's a bit of a lag to deploy, but it is a really simple process.

I hope this helps somebody.

 

tonantetonante
Thanks I will definitely pass this info along !
Karen WheelerKaren Wheeler
Paul, was excited to hear about this - but sadly when I went to the MavensMate site, it has been shut down. :-( Totally bummed. 
Paul WorltonPaul Worlton
The MavensMate site is shut down but the packages are still available on Github.  https://github.com/joeferraro/MavensMate-Desktop/releases
Paul WorltonPaul Worlton
The MavensMate site is shut down but the packages are still available on Github:  https://github.com/joeferraro/MavensMate-Desktop/releases

I believe Salesforce is moving towards a .NET Code solution but I'm not sure if it is viable yet.