+ Start a Discussion
Angie YzaguirreAngie Yzaguirre 

writing a class to an old trigger

I am trying to deploy a trigger, but a very old trigger is holding up the process because it does not have any code coverage:

User-added image

Can anyone help me write a class to make this code have at least 1% coverage?? 
Ankit AroraAnkit Arora

If you are deploying a trigger then you must have covered the coverage for that trigger, then I think you know how to write a test class. Even if this trigger is not in your current environment, you can write a test class for it.

Say

Benchmark__c bench = new Benchmark__c() ;

This will initiate your trigger but you should know what all are your required fields you need to enter.

Thanks
Ankit

James LoghryJames Loghry

Like you mentioned, triggers need "non-zero" unit testing, meaning if you invoke the trigger via a test method, you should be able to deploy if your overall code coverage is > 75%.  That being said, all you should need to do (for the bare minium) is to create a test method that inserts a Benchmark__c record.  Ankit was ALMOST correct, but he left out the insert statement.  Here's what your test method might look like:

@isTest
private testCalculateRollups{
    static testmethod void testInsert(){
        Benchmark__c bench = new Benchmark__c();
        insert bench; // should invoke your trigger.
    }
}

In addition to the bare bones test, you'll also want to add criteria to test out the various conditions in the trigger, along with System.assert calls to verify your trigger is working properly.  For more on that see the following sites:

Angie YzaguirreAngie Yzaguirre
Hello James - That is very helpful, but I am actually very new to the trigger code writing.  I was able to get help through the forums on the actual code writing.  I tried to insert the class code that you wrote above in my sandbox, but I received this error:

[Error] Error: Compile Error: unexpected token: 'testCalculateRollups' at line 2 column 8

Along with that error, is there a way to know what the various conditions of the trigger are?