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
anillllanillll 

Test Class Coverage

trigger AddQuickLead on Lead (after insert) {
    
    for (Lead l : Trigger.new) {
       
        
        Quick_Lead__c reg = new Quick_Lead__c(
            Name=l.Name,
            Email__c = l.Email,
            Street_Address__c = l.Street,
            city__c = l.City,
            state__c = l.State,
            Country__c = l.Country
          );
          
          if(l.FirstName==null)
        {
        reg.Name= l.LastName;
        }
        else
        {
        reg.Name= l.FirstName+''+''+l.LastName;
        }
        
        insert reg;
    }

 how to get coverage for line:

reg.Name= l.FirstName+''+''+l.LastName;
jungleeejungleee

Hi , 

Insert two reccords in the test one with first name null and other one tih some value in it. This will cover the if and else part. So that should cover the line which you have pointed out.

 

Hope it help!!

 

Regards

Sam

logontokartiklogontokartik

Here is the test class

 

@isTest
private class testTrigger {

static testmethod void testTriggerMethod(){

List<Lead> leads = new List<Lead>();
leads.add(new Lead(FirstName='Test',LastName='Last',Email='test@test.com',Street='Test Street',City='Test City',State='TX',Country='USA',Status='Open - Not Contacted'));
leads.add(new Lead(LastName='Last2',Email='test2@test.com',Street='Test Street2',City='Test City2',State='TX',Country='USA',Status='Open - Not Contacted'));

Test.startTest();
insert leads;
Test.stopTest();
}
}

 

klekle

I would add a system.AssertEquals

 

if you added your test data as    testLead1.add(new Lead(FirstName = 'Mary', LastName = 'Smith', Company='Widgets and Co', Email='sd462fe@sdsdfs.com', City = 'Herndon'.....
   

then you could assert that the name is equal to FirstName + LastName:

 

       Quick_Lead__c ql = [select id, Name from Quick_Lead__c where createdDate = TODAY and City__c = 'Anytown'];
          
            system.AssertEquals(ql.Name,'Mary Smith');