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
Dheeraj ChawlaDheeraj Chawla 

Can anybody help me... my test class does not showing 75% coverage. I write the class for trigger.

Can anybody help me... my test class does not showing 75% coverage. I write the class for trigger.
it does not cover line number 13, 14, 15 and 19. Can anybody please tell me where I am lacking.
MY trigger is----------

trigger TriggerOnLead on Lead (before insert, before update) 
{
    public List<lead_scoring_rule__c> obj=[Select active__c,rule_type__c,points__c, field_name__c,operator__c,value__c from lead_scoring_rule__c];
    public Map<String, Schema.SObjectType> leadMap = Schema.getGlobalDescribe();
    Schema.SObjectType leadSchema = leadMap.get('Lead');
    Map<String, Schema.SObjectField> leadfield = leadSchema.getDescribe().fields.getMap();
    for(lead l: trigger.new)
     {
          Double points=0;
          System.Debug('ttttttt');
       for(lead_scoring_rule__c ld:obj){
            System.Debug('lddddddddddd='    +    ld.field_name__c);
            System.Debug('fffffffffff='+l.get(ld.Field_Name__c));
            if(ld.active__c==true){
                if( l.get(ld.Field_Name__c)==ld.value__c){
                    points=points +ld.points__c;
                    System.Debug('Points Scored====='+ points);
                }
            }
            l.lead_score__c=points;
       }
     }
}
------------------------------------------------------------------------------------------------------------------------------------
And the test class is----




@isTest
private class TestTriggerOnLead {
    static testMethod void myUnitTest(){
        Lead_Scoring_Rule__c s=new lead_Scoring_Rule__c(Active__c=true, points__c=10,field_name__c='city',operator__c='==',value__c='Gurgaon');
        //List<lead> obj=new list<lead>();
            lead l=new lead(firstname='Test1',lastname='xyz',Company='Mansa', status='Not-Contacted',city='Gurgaon');
            insert l;
            insert s;
            lead ld=[select lead_score__c,city from lead where firstname='Test1' ];
            lead_scoring_rule__c nc=[select active__c, points__c,value__c from lead_scoring_rule__c where points__c=10]; 
            //System.Debug(ld.lead_score__c);
            if(nc.active__c==true){
                if(ld.city==nc.value__c){
                    ld.lead_score__c=nc.points__c;
                }
            }
            //System.assertEquals(l1.lead_Score__c,5);
            //System.assertEquals(l2.lead_Score__c,10);
    }
}

 
Best Answer chosen by Dheeraj Chawla
Arunkumar RArunkumar R
Hi Dheeraj,

Can you try the below test code,
@isTest
private class TestTriggerOnLead {
    static testMethod void myUnitTest(){
        Lead_Scoring_Rule__c s =new lead_Scoring_Rule__c(Active__c=true, points__c=10,field_name__c='city',operator__c='==',value__c='Gurgaon');
		 insert s;
		 
            lead l=new lead(firstname='Test1',lastname='xyz',Company='Mansa', status='Not-Contacted',city='Gurgaon');
            insert l;
    }
}