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
MDXHikerMDXHiker 

Issues with code changes push to production

I have a few classes and triggers in Production. I needed to make some changes to one class.
 
I did that change and tested in Sandbox. Now when I try to deploy it via Eclipse the change is not recognized at all during deployment.
I tested the test cases and they are all above 75% in Sandbox. I cant test them in production as the changes are not recognized
 
How do I force the IDE to recognize the change?
 
Thanks
JonPJonP
Could you be more specific about what you mean when you say, "the change is not recognized at all during deployment"?

What Force.com IDE, Eclipse, and OS version are you using?

Before you deploy to production, do you perform a Force.com > Refresh from Server on the "src" folder to make sure you have the latest files from Sandbox in your Force.com project?

Assuming you are running the Winter '09 Force.com IDE, if you go to Help > Show Force.com IDE Log are there any exceptions in the IDE log?

Jon
salesforce.com Product Manager
MDXHikerMDXHiker

Jon,

I do refresh my Sandbox project. But I usually create or edit the production project directly as I have many other things which I don't want to promote to production from my sandbox.

Also I do not have the Help->IDE Log option. So I guess I need to get Winter 09 IDE

My Force.com IDE is v12.0.2.xxxxxx, Eclipse is 3.3.2. Thanks

JonPJonP
MDXHiker,

Here's what you should do:

1. Install the Force.com IDE for Winter '09.

- There is no direct upgrade path from the previous Developer Preview releases of the IDE, so the easiest way to "upgrade" is to install a new copy of Eclipse 3.3.2, with a new workspace, and install the Force.com IDE for Winter '09 into it.  If for some reason you cannot do this, you will need to uninstall the old Force.com IDE plug-in and delete all your Force.com projects before installing the new plug-in.

2. Create a new Force.com project against your Sandbox org, and in Step 2 of the wizard select "Choose metadata components" then use the "Choose Metadata Components" dialog to select just those files you want to deploy to production.

3. Once the IDE has created your project and downloaded the selected components from Sandbox, right-click on the "src' folder and select Force.com > Deploy to Server to push the entire set of classes/triggers (including required tests) to production in a single transaction.

We strongly recommend against creating Force.com projects directly against production organizations, as all the restrictions around code coverage minimums for deploying apply every time you save a file.

If you still have problems after completing these steps, post your IDE log contents and we'll take it from there.

Jon
MDXHikerMDXHiker

Jon,

I was able to upgrade to the versions you mention. The changed class is now being detected. Thanks.

A related question to this - in sandbox the unit tests written added up to more than 75%

But when I try to push that to production ( with selected components ) the test coverage is shown less than 75%. The problem exists iwth triggers and they are not covered.

Can you please point me to some trigger unit test examples? Thanks

JonPJonP
The most common cause for seeing different code coverage numbers in Sandbox vs. production is creating non-portable tests.  Typically this means writing tests that assume certain records exist in an organization, for example writing a test that queries for a specific record by Id.  In Sandbox, the test passes and executes the complete code path you intended, but the same record doesn't exist in production so the test behaves differently.

The best practice here is to create all the records you need within each test method, then call System.startTest() when your actual test should start (allowing you to create test data without counting against your to-be-tested code's governor limits, though looser limits still apply).  DML statements (insert/update/delete) performed within a test method are not committed to the database, so you can do whatever you need to set up your test without worrying about impacting production data.

Also, if your triggers are not covered at all, the way to test them is to perform the appropriate DML statement within a test method.  For instance, if I want to test a before update trigger on Account, in my test method I'll want to insert and then update an Account so my trigger will fire.


You should find useful examples of test methods in the Apex Language Reference, Force.com Developer's Guide, and Force.com Cookbook.  I don't have particular chapters/examples I can point you to offhand, though.

http://wiki.apexdevnet.com/index.php/Documentation

MDXHikerMDXHiker
Also how does the publish API work ? If I have 5 classes in prod and I need to update only one class, is the unit test coverage calculated against all the existing classes and triggers? Does this run against the existing ones or the ones which are going to be published to production?
MDXHikerMDXHiker
No test code in Sandbox has any hardcoded values, so this should be portable.
 
More strange is that code coverage results I get while tryingt o deploy compains about the code which already exists in production. For example there is a trigger which was pushed earlier this year with its respective test cases.
When I run all tests in prod ( Salesforce UI ) the coverage is 86%. But the publish API complains the code coverage is below 75%.
Thanks
JonPJonP
Deploying to production runs all tests in the production organization, including any new tests you are deploying, and excluding tests in installed managed packages from AppExchange (which still have to run and pass when the package is installed).

On the code coverage issue, as a quick test try deploying an empty Apex class with the @isTest keyword in the line above your class declaration.  This means the class can only contain test methods, and it will not be counted against your organization limits for max lines of Apex code, nor should it actually affect your code coverage %.  This basically simulates Run All Tests, ignoring the new code you want to deploy.

If the code coverage number is different from Run All Tests in the web UI, then it's your new code that's causing the overall coverage number to drop below 75%.  If the code coverage numbers are different, you should open a support case.