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
michael davis 67michael davis 67 

0 coverage for my trigger helper class???????????????need help. what am I doing wrong???????


Hi All,

I was able to get 75% coverage for my trigger by writing the test class below, however, the code coverage for the trigger helper class is 0, what am I doing wrong?
Here is my trigger:
trigger sessy on session__c (before insert, after insert, after update, before update, before delete) {
    if(recursive.runonce()){
       
        sess  handler = new sess();       
       
       
if(trigger.isbefore && trigger.isupdate){
     sess.onbeforeupdate(trigger.old, trigger.new,trigger.oldmap, trigger.newmap) ; 
         }   
   
   
}
}
here is my helper class:

public class sess {
    public static void onbeforeupdate(list<session__c> oldlist,list<session__c> newlist,map<ID, session__c> oldmap, map<ID, session__c> newmap){
       
    for (AggregateResult ar : [Select Count(ID) numRecs, Alex__c acctid From event__c Where Alex__c In:Trigger.New Group By Alex__c]){ Id acctId = (Id) ar.get('acctId');
    session__c acct = (session__c)Trigger.newMap.get(acctId);
    acct.mike__c = (Decimal) ar.get('numRecs');
}
          
   
    }
   
  }
and here is my tes class for the trigger -HELP PLEASE, why is the helper class gettig 0 coverage?

@isTest
public class sesstest{
static testmethod void     onbeforeupdatetest(){
 Session__c SEPT = new session__c () ;
 
 SEPT.name = 'hippy';
 SEPT.desc__c = 'rte';
 
 
 Insert SEPT;
 
 
 event__c justy = new event__c () ;
 
 justy.name = 'hoppy';
 justy.alex__c = sept.id;
 
 
 
 insert justy;
 
 SEPT.desc__c = 'rtfff';
Test.Starttest();
 Update SEPT;
sess sc = new sess();
 
Test.StopTest();
SEPT = [select ID, Mike__c from session__c where id = :sept.id];
aggregateresult jkl = [select count(ID) ctt, Alex__c tyt from event__c where Alex__c =:sept.id group by Alex__c];
System.assertequals(SEPT.MIKE__C,null);
}}
Best Answer chosen by michael davis 67
PawanKumarPawanKumar
Hi Michael,

Great to know. Please give me a favour by marking best answer.

Regards,
Pawan Kumar

All Answers

PawanKumarPawanKumar
Hi,
Please try with below and let me know.


trigger sessy on session__c(before insert, after insert, after update, before update, before delete) {
 if (trigger.isbefore && trigger.isupdate) {
  sess.onbeforeupdate(trigger.old, trigger.new, trigger.oldmap, trigger.newmap);
 }
}

 public class sess {
  public static void onbeforeupdate(list < session__c > oldlist, list < session__c > newlist, map < ID, session__c > oldmap, map < ID, session__c > newmap) {

    for (AggregateResult ar: [Select Count(ID) numRecs, Alex__c acctid From event__c Where Alex__c In: newlist Group By Alex__c]) {
     Id acctId = (Id) ar.get('acctId');
     session__c acct = (session__c) newmap.get(acctId);
     acct.mike__c = (Decimal) ar.get('numRecs');
    }
}    
michael davis 67michael davis 67
Hi PawanKumar, I made the modification, you posted. The test passed but the developer console still shows 0 coverage for the helper class, the trigger is at 75% coverage. is it possible to deploy the trigger in its helper class with this coverage? can I possibly use eclipse or some other method to get around the mandatory 75% coverage? Thank You
PawanKumarPawanKumar
Hi Michael,

Please try below and let me know.

trigger sessy on session__c(before update) {
// if (trigger.isbefore && trigger.isupdate) {
  sess.onbeforeupdate(trigger.old, trigger.new, trigger.oldmap, trigger.newmap);
// }
}
michael davis 67michael davis 67
HI Pawankumar, IT WORKED!!!!! :) Thanks man you are the best!!!!!!
PawanKumarPawanKumar
Hi Michael,

Great to know. Please give me a favour by marking best answer.

Regards,
Pawan Kumar
This was selected as the best answer
michael davis 67michael davis 67
For Sure. Done. Thanks Man:)