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
Kitty SKitty S 

Problems with code coverage/deleting unwanted code - completely stuck :(

I'm really struggling with Apex and the code coverage of our org.  I'm not a developer and I'm completely stuck.

We have 74% code coverage in our production org. We also have 4 Apex triggers and 15 Apex classes that are completely redundant and relate to a custom object that is never used.  We want to delete the complete object and all related code.  The Apex classes all fail so getting rid of them would bring our code coverage up to a decent level.

I can't seem to get rid of them. I can't deactivate the triggers in Sandbox and deploy them to production because code coverage is not high enough.  Plus some of our code also has 0% coverage. I've had Eclipse installed but when I try and make one of the unwanted triggers inactive I get errors:

System.QueryException:List has no rows for assignment to SObject
System:Exception:Assertion Failed
System:Exception:Assertion Failed
System:Exception:Assertion Failed
And two 'System.DmlException:Update failed' that trigger a validation rule on the Account in the production org

How do I unravel this so that I can get rid of this code?  Is there a simple way?  I can't deploy anything that requires code changes at the moment so I have to fix it somehow.

Can anyone help explain it in simple terms so that a dummy can understand it please?

Thank you.
rizwan ahmed 16rizwan ahmed 16
click setup -
Then on left side top in quick find box type objects then click  objects and delete which objects  u dont require.
similary to classes
click setup -
Then on left side top in quick find box type  apex classes then click on apex classes and delete which classes u dont require.
similary to triggers
click setup setup-
Then on left side top in quick find box type  Apex Triggers  then click on apex triggers and delete which triggers  u dont require.
mark it as best answer  if it was use full for u 
Kitty SKitty S
I can delete the Apex classes and triggers in the Sandbox but not directly from Production, that's the bit I am having problems with.
rizwan ahmed 16rizwan ahmed 16
hope this link will be use full for you.
http://salesforce.stackexchange.com/questions/5776/deleting-triggers-classes-from-production
An easy way to do this is as follows:

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 file and change the status of the class to "deleted"
3.Save to server

Observe the status of the class in the example below:
<?xml version="1.0" encoding="UTF-8"?>
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>23.0</apiVersion>
<status>Deleted</status>
</ApexClass>

You should try this technique in sandbox and become comfortable with it before attempting in production. Double-check the class name before deleting.
 
Kitty SKitty S
Hi, thanks for the link.  I've tried deleting the classes but I get an error each time I do. 

Errors like this:
System.QueryException:List has no rows for assignment to SObject
System.DmlException:Insert failed. First exception on row 0; first error: DUPLICATE_USERNAME...

As the object has never actually been used, wasn't built by me and is at least 3 years old, I don't know what is triggering the error so don't know what to do to prevent it.  How can I get round this?

Will it work to comment out all the unwanted classes in the Sandbox and then deploy them to Production?  Then after that try and delete it from production using Eclipse?

Thanks.
rizwan ahmed 16rizwan ahmed 16
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.