1

Today I went to deploy a small piece of code from a sandbox to production using a change set. Simple..usually. This failed because it told me my overall code coverage is less than 75% (59% to be precise). I am not a developer but from what I can see there seems to be a couple of old bit of code that are no longer required, and a couple that don.t have test classes.

My first question is how do i easily delete the old code from production. I've tried changing the status to 'Deleted' in the XML and deploying but even when it shows as successful the APEX class is still showing in salesforce. Any ideas why that might happen?

Secondly, how would I go about deploying more code (the test cases) to a live environment that when I try to deploy is telling me I cant because my code coverage is less than 75%!!!

Any help and guidance much appreciate

  • Time to bite the bullet -- get your sandbox in such a state that when you run all tests, you are at > 75% code coverage ; bite harder and work towards 90+% as you'll want to have a good regression suite to use throughout the system life. Don't just do code coverage, add system.asserts to verify proper system behavior under negative and positive cases. Then deploy. – cropredy Jun 30 '15 at 16:52
2

How to Disable or Delete an Apex Class or Trigger from a Production Org:

https://help.salesforce.com/apex/HTViewSolution?id=000006188

  • Some more text would be nice. We generally discourage link-only answers. – sfdcfox Jun 30 '15 at 20:32
1

Deleting old code is not a very straightforward thing. You really have to be familiar with a development environment like Eclipse or MavensMate or maybe even Asite.io. Or you have to purchase a deployment tool from the AppExchange.

However you can try commenting out all of the unused code using /* */ comments. The idea for a trigger for example would be to have it look something like

trigger AccountTrigger on Account (before update) { /* This is the start of a comment Code would be here This is the end of a comment */ }

You'd all need to comment out all of the Apex Classes that the Trigger might reference and all of the Test Classes that test the Trigger.

This is a bit dirty, but it should work.

You also asked, how do you update test coverage when it's too low. This is actually very easy. In the Sandbox you simply add more test coverage, include the new test class or testMethods in your Change Set. When Salesforce goes to deploy the new code it does NOT run the old test first, it actually puts the new code in and runs all of the tests. So if your code coverage in Sandbox is 80% then in Production it should be close to that as well (assuming the test classes/methods are in the change set and are written properly).

Hope this gets you started in the right direction.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.