+ Start a Discussion

ORG locked - Apex Classes and Triggers can't create, edit and save _ Strange Error

A couple of days ago I posted a similar question on the forums, I couldn't edit any exisitng apex class or trigger. I got an error message on eclipse:
 "Average test coverage across all Apex Classes and Triggers is 4%, at least 75% test coverage is required - line 1 Force.com code coverage warning"
so the solution was to create a sandbox and then upload the changes from there. Now, I could modify the code on the sandbox, but I cannot deploy it to the production org. I keep getting the same error. I am deploying to production via the ant, and even though the class I have modified has code coverage, it wouldn't let me deploy it. It keeps giving me the same error. 
Eclipse SDK 
v: 3.4.0
Build id: I20080617-2000 
Force.com IDE
v: Summer '09 (16.0.0) 
Trying to do it directly in the org (Setup > Develop > Apex Classes) I don't have the Edit | Del buttons, just the WSDL | Security ones. 
So I am completely locked, I can't do anything in the org. Is there a way to unlock it? Has this happened to someone before? 

You cannot Edit/Delete Apex Classes or Triggers in your production org through the user interface. That's why you do not see the buttons (and you never will in production). You will continue to get that error until your test class covers at least 75% of the code. From your error message, you only have 4% coverage... so you still have some work to do before the code is deployable!

If you post your code & test class we may be able to give you some pointers :smileyhappy:



Message Edited by CaptainObvious on 09-25-2009 09:47 AM

Thanks Cap!


So, before being able to deploy to production. I need to take my code coverage of the sandbox to at least 75%, then deploy all the code together, including the deletion of old classes. That way it would let me do the deploy right?


Do you have any idea why did it let the previous programmers deploy everything to production with the 4% code coverage? 




It may be that the code in production meets the requirements- but you may have untested classes/ triggers in your current Eclipse Project. If you try deploying the entire project to production, the cumulative test coverage will drop because of the untested code.

Try selecting only the components you want deployed from the current project or create a new project with only the class/trigger you need deployed.

To determine the current code coverage in production, create a project in Eclipse using the Production/Developer Edition Environment. Include all Apex & Visualforce components (default). Once the project is created, drill down to src>classes, right click the classes folder, select Force.com> Run Tests. It may be a good idea to bring all code up to 100% coverage before creating new triggers :smileyvery-happy:

Message Edited by CaptainObvious on 09-25-2009 10:32 AM

Well, I think I didn't explain the overall situation. 


I need to modify a production org that has a bug. So in order to modify it, I created a sandbox and changed a couple lines of code in one class. Now, when trying to deploy the new class to production, I get the 4% error.


I don't think that production meets the 75% code coverage since I am seeing the code and most classes don't have test methods. The ones that have, only cover a few parts. I have just refreshed the eclipse projects, both sandbox and production and they are both the same except for the class I modified in sandbox.


In the class I changed I built the test method and it has a 100% code coverage. Then tried to deploy it alone and keep getting the error. The other classes in production or sandbox, none has code coverage and I am only trying to deploy my class, not the whole project. 


It will be a big effort to write test methods for all the classes, take them to 75% and then still be unable to deploy to production.  


I've tried getting my class to 100% and it still doesn't let me deploy. So what I want to be really sure, is that if I add test methods to all classes in the sandbox, and get them to at least 75%, deploy them all together it will let me do the deploy and it will not keep giving me this error. 


I hope that this gives an idea of the situation and would really appreciate some tip. Thanks!!!! 





Yes, if the error you're receiving on deploy is that your code doesn't meet the test coverage requirements, then writing tests so that the entire production organization meets the 75% requirement will solve the problem, and you will be able to deploy.




One reason the code is in Production with such a low test coverage could be that it was written/deployed while you were in a trial org.  I've seen that before where an EE trial allows creation/modification of classes/triggers right in Production but then when the trial ends you are stuck having to create a Sandbox and get your test coverage % up.


Also, you can deploy only a single class (ie the one with the bug) and then would need only test coverage for that class to meet 75%.  If you are using Eclipse to deploy, you simply select only the class and its test class in the deployment plan and it will evaluate the test coverage in that class only.  This should avoid having to create test code for all the other classes until needed.




You're correct about the EE trial possibly allowing code to be deployed without test coverage.  However, in a non-trial production organization, you must have 75% or greater code coverage across ALL classes and triggers in your organization (excluding any AppExchange managed packages, which must meet this 75% requirement themselves) or your deploy will be rejected.  It is not limited to the files you're deploying; each time you deploy to a production organization, all test methods are run--those in your new files as well those already in the organization.



So, from this I am taking that I cannot update my class in production. Correct me if I am incorrect in the following thought process.
  1. Creat a sandbox
  2. Edit in the sandbox
  3. Deploy to the production
Is this all correct. If so, I now need to learn how to deploy from the sandbox. Any advice? Just trying to get straight answers from those who are actually using it.  I still haven't fully figured out the SF jargon