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
Pedro SallesPedro Salles 

How to delete an Apex class from production without a 75% code coverage?

Hello, I'm working on a production org and need to delete apex classes and objects, however my code coverage is at 56% and I can not raise any other class into the production environment. It's 2012, and I can not find a reason why she lost coverage other than updates from salesforce. Has anyone experienced this situation know how to fix this problem?

Thanks

Pedro
Best Answer chosen by Pedro Salles
Khan AnasKhan Anas (Salesforce Developers) 
Hi Pedro,

Greetings to you!

An Apex Class or Trigger must be removed from a production instance if it's blocking a deployment or is no longer needed. Since Apex code can't be modified directly within a Production organization, it requires steps using Developer tools, like the Force.com IDE.

Remove or delete Apex Class or Trigger

1. Install Force.com IDE (https://developer.salesforce.com/docs/atlas.en-us.212.0.eclipse.meta/eclipse/ide_install.htm).
2. Connect to the Sandbox Instance using IDE and find the class or trigger that you want to delete.
3. Open the matching .xml file, and change the Status XML tag from Active to Deleted. 
4. Or to disable the trigger change it to Inactive.
NOTE: Apex class Status can only be changed to "Active" or "Deleted," not "Inactive".
5. Save the file.
6. Select the two files (Code and XML) using "Ctrl-click," and then right-click on one of them.
7. Select Force.com | Deploy to server.
8. Provide your credentials for the Production org and follow the steps.

Reference: https://help.salesforce.com/articleView?id=000006188&type=1

Also, please refer to below link which might help you further.

https://sfdcfanboy.com/2017/11/24/a-tip-a-day-24-3-ways-to-delete-an-apex-class-from-production/

https://salesforce.stackexchange.com/questions/5776/deleting-triggers-classes-from-production

https://developer.salesforce.com/forums/?id=906F0000000BNQ5IAO

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks and Regards,
Khan Anas

All Answers

Khan AnasKhan Anas (Salesforce Developers) 
Hi Pedro,

Greetings to you!

An Apex Class or Trigger must be removed from a production instance if it's blocking a deployment or is no longer needed. Since Apex code can't be modified directly within a Production organization, it requires steps using Developer tools, like the Force.com IDE.

Remove or delete Apex Class or Trigger

1. Install Force.com IDE (https://developer.salesforce.com/docs/atlas.en-us.212.0.eclipse.meta/eclipse/ide_install.htm).
2. Connect to the Sandbox Instance using IDE and find the class or trigger that you want to delete.
3. Open the matching .xml file, and change the Status XML tag from Active to Deleted. 
4. Or to disable the trigger change it to Inactive.
NOTE: Apex class Status can only be changed to "Active" or "Deleted," not "Inactive".
5. Save the file.
6. Select the two files (Code and XML) using "Ctrl-click," and then right-click on one of them.
7. Select Force.com | Deploy to server.
8. Provide your credentials for the Production org and follow the steps.

Reference: https://help.salesforce.com/articleView?id=000006188&type=1

Also, please refer to below link which might help you further.

https://sfdcfanboy.com/2017/11/24/a-tip-a-day-24-3-ways-to-delete-an-apex-class-from-production/

https://salesforce.stackexchange.com/questions/5776/deleting-triggers-classes-from-production

https://developer.salesforce.com/forums/?id=906F0000000BNQ5IAO

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks and Regards,
Khan Anas
This was selected as the best answer
Pedro SallesPedro Salles
Hi Khan, I followed the steps you described in the answer and it worked.

Thank you very much