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

Trigger Deployment Difficulties...Force IDE, Code Coverage

I have read several posts and done quite a bit of searching. I'm still having trouble. I have the following trigger:

trigger opportunityContactRoleUpdate on Opportunity (after Insert, after Update)

    for(Opportunity o :
        if((o.StageName == 'Closed Won (Recurring)' || o.StageName == 'Pilot (Recurring)') && o.Recurring_Opportunity__c=='Yes' && o.Probability>=90.0 && o.Client_Id__c==4944)
            Date a =;
            Date b = a.toStartOfMonth();
            Date c = b.addDays(-1);
            List<Opportunity> oldOpps = [SELECT id FROM opportunity WHERE Client_Id__c = :o.Client_Id__c AND closedate <= :c ORDER BY closedate DESC LIMIT 1];

            List<OpportunityContactRole> ocrs = [SELECT id, OpportunityId FROM OpportunityContactRole WHERE OpportunityId=:oldOpps[0].id];
            for(integer i=0; i<ocrs.size(); i++)
                ocrs[i].OpportunityId =;
                update ocrs;

 For which I created an Apex Test class to get coverage on:

public class opportunityContactRoleUpdateTest {

 static testMethod void myTest()
  Opportunity o = new Opportunity(name='Dave 1', stagename='My Stage 1');
  insert o;
  o.Name = 'Dave 1 Updated';
  o.Stagename = 'My Stage 1 Updated';
  update o;


I created this based on another post - because the insertion and create of this opportunity would cause my trigger to fire, give me enough coverage.

I'm developing in Eclipse using the Force IDE. These are some of the problems I'm having.

1. I cannot save to the server more that the class definition of my Test class. The body of my class never saves to or gets to my production environment using the 'Save to Server' or 'Synchronize with Server' options in the Force IDE - although it runs, it never saves more than the inital class definition.

2. After I do get it on the server and run the test on it, how do I 'activate' the trigger (which by the way I can save to the server just fine...) Do I have to use the ant method to activate it, or can I do it with the Force IDE...I'm not having any luck finding the method to 'activate' the trigger.

3. I can 'run tests' on my small apex class that I created and it shows me 100% coverage...however it looks to me like it's telling me 100% of the testclass run, and not 100% of my trigger was covered...I would like to 'run all tests' on my apex class from SF, but as I said, i can't get it there...

I'm pretty stuck here. Any suggestions would help me out.


Updated: I downloaded and installed the latest Force IDE. I create a new workspace, and a new project - synchronizing with our production env. Now I'm having additional errors when trying to run my test class. I get:

INVALID_OPERATION: Cannot specify both runAllTests and specific RunTests

This happens when I right click on the test class, select 'Force' and then run tests.

Message Edited by dave_mwi on 02-29-2008 12:58 PM

Message Edited by dave_mwi on 02-29-2008 01:00 PM
I have some problem too!

Here's a way to deploy my Apex triggers to production using the Eclipse IDE:

  1. Before you do anything, make sure you're on the perspective on Eclipse.
  2. Right click on the project you originally created the Apex Class/Trigger in (in my case, in sandbox), select " - Deploy to Server".
  3. In step 1 of Deployment, enter your Salesforce production's credentials. If you're behind a proxy server, enter that information as well.
  4. Step 2 is optional but recommended (basically, creating backups before you overwrite your project in production)
  5. In step 3, you're going to select all the files you want to deploy to your production. By default, all files will be selected.
  6. After that, select on deploy and your trigger/Apex classes you selected in the previous step will be deployed to production.

Just to let you know, once you deploy apex triggers to production, there's no simple way to deactivate them currently. One way to deactive them is to modify the "IsActive" tag within the trigger's xml file to false and then redeploy it to production.

I'm too fairly new at developing Apex code, but I hope this helps.

Thanks! It works.
Did you reset security token for sanbox account or use token from parent account?

It looks like most of your trigger's functionality is inside a conditional statement, which evaluates to False when exercised by your test method - so you wind up with only a small portion of your trigger being 'covered'.  This is the likely cause of your trigger not being deployed.  I would modify your test method if I were you, to set up that Opportunity record's fields so that your trigger does get fully exercised.

You will probably also want to restructure that trigger to pull those SELECTs out of the loop - otherwise you risk hitting governor limits in bulk context. 


My experience with Eclipse and deploying has been up and down. Right now it's down, but it was working so well for a period of time. So, in part, I'm experiencing the same issues you're experiencing with running tests and having the code coverage applied to the test class instead of the trigger, and I don't know how to fix this--this JUST started occurring. On the other hand, testing and deploying can all take place within Eclipse.

Problems I was experiencing previously were related to having the project's "SOAP Endpoint" (in Properties...) set to the production server instead of the testing server ( Once I set the SOAP endpoint to the testing server, saving to the server would cause all the code to save to my sandbox environment (which is free with Unlimited Edition). Synchronizing with the server would cause synchronization between items in the sandbox and local items. When I ran tests, it worked as expected: tests were run against my trigger and utility classes and code coverage applied to them instead of my test class itself. And finally, in the deploy phase, I would select the production URL for the SOAP endpoint, validate the deployment plan, observe the code coverage, and the trigger and utility classes would deploy to production already set to 'active'.
All, thanks for your responses. This is what I've figured out so far - keep in mind this is in my IDE that all this is happening...I have not changed any settings other than fonts and connection information to my SF environment:

1. My Eclipse was not showing me enough information about what was going on with my code. The way I figured this out was by running the eclipse executable with the following option from the command line (dos window):

c:\path\to\eclipse.exe -consoleLog (also the same on Linux, just not .exe)

In the command window that is launched you can see 'much' more information. From this window I was able to see actual percentages of my test coverage - something that was not accurate in my eclipse IDE...which brings me to my next point.

2. Test coverage is automatically run when you try to 'save' your trigger. You can see the results of this in the command window.

3. When you 'save' your trigger, the IDE also attempts to save it to your SF environment (prompting the test coverage execution...) - at least mine does. If it fails, you will see either a red 'x' icon (an error) or a yellow '!' icon (warning) somewhere along the left hand gutter of the file. Examine the command window to see why if failed. *a lot* of info will scroll by, but after it's done, it's usually about 5-10 messages up from the bottom.

4. To activate the trigger - it was quite easy once my trigger was saving to SF because of no errors and proper test coverage. There is a tab at the bottom of the trigger file labled 'metadata'. Click on that and change the 'false' value in the active element to 'true' but only if you want to enable your Trigger!!

So, to sum up -
- I don't know if these have been caused by settings in my eclipse, but it was never outputting enough info in the IDE for me to know exactly what was going on.
- I've never had to use the 'deploy' option to do any of this. Only 'save' or 'save to server' to get my changes onto my SF evironment.

Anyway, this is what I've had to do to make sense of using the IDE...anyone else having similar 'growing pains' ?? I hope this helps some others...

Anand SinghAnand Singh
Thanks for posting such important information on deployment.
I had been searching it from many days.
I'm glad it's helping someone else other than me. Keep in mind that it may differ depending on your version of the IDE and the settings you might have, but this is how mine is currently functioning...
Thanks for the post, Dave.  I'm still coming up empty.  My code right now is brain-dead simple.  Here's the trigger:

trigger Contact_SSN on Contact (before insert, before update) {
    for (Contact {
        cntct.SSN2__c = cntct.SSN__c;

And the test class:

public class ContactTest {
    static testMethod void testContactTrigger() {
        Contact cntct = new Contact();
        insert cntct;

But it won't save, insisting that I have 0% test coverage.  If I try to RunTests on the class file I get the same INVALID_OPERATION error that someone further up this thread noted.  Am I missing something key here?