• Eduardo Costa 4
  • NEWBIE
  • 30 Points
  • Member since 2016

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies

Hi all,

I have a test class that I am trying to set a RecordTypeId to (see below). I need the record type id because I have a validation rule in production that will prevent the deployment of this test class without the record id set. 

When I hardcode the recordId into the test class, I get 100% coverage. When I try to dynamically assign the id, however, I get 50% coverage. 

Can anyone help with what I am doing wrong? 

Thanks!

Tasia

@isTest
public class UpdateCaseWhenLeadConvertedTest 
{  
    private static testMethod void LeadConvertedTest()
    {
        
        Lead olead = new Lead(LastName='Test',FirstName='Tester',Status='Known',Company='CD Test');
        insert olead;
        
        Case c = new case (Status ='New', Priority = 'Medium', Origin = 'Email');
        c.Lead__c = olead.Id;
        c.RecordTypeId =  Schema.sObjectType.Case.getRecordTypeInfosByName().get('Customer_Service_Record_Type').getRecordTypeId();
        insert c;

        Database.LeadConvert lc = new database.LeadConvert();
        lc.setLeadId(olead.id);
        lc.setDoNotCreateOpportunity(true);
        lc.setConvertedStatus('Converted w/out Opp');

        Database.LeadConvertResult lcr = Database.convertLead(lc);
        System.assert(lcr.isSuccess());
        
        
        List<Case> lstCase = [Select id ,ContactId, Status, Type from Case where id =:c.id ];
        System.assert(lstCase.size() > 0 );
        System.assert(lstCase[0].ContactId !=null );
        System.assertEquals('Closed', lstCase[0].Status);
        System.assertEquals('Web Account Approved', lstCase[0].Type);
        
    }
}

Hi all,

I have a test class that I am trying to set a RecordTypeId to (see below). I need the record type id because I have a validation rule in production that will prevent the deployment of this test class without the record id set. 

When I hardcode the recordId into the test class, I get 100% coverage. When I try to dynamically assign the id, however, I get 50% coverage. 

Can anyone help with what I am doing wrong? 

Thanks!

Tasia

@isTest
public class UpdateCaseWhenLeadConvertedTest 
{  
    private static testMethod void LeadConvertedTest()
    {
        
        Lead olead = new Lead(LastName='Test',FirstName='Tester',Status='Known',Company='CD Test');
        insert olead;
        
        Case c = new case (Status ='New', Priority = 'Medium', Origin = 'Email');
        c.Lead__c = olead.Id;
        c.RecordTypeId =  Schema.sObjectType.Case.getRecordTypeInfosByName().get('Customer_Service_Record_Type').getRecordTypeId();
        insert c;

        Database.LeadConvert lc = new database.LeadConvert();
        lc.setLeadId(olead.id);
        lc.setDoNotCreateOpportunity(true);
        lc.setConvertedStatus('Converted w/out Opp');

        Database.LeadConvertResult lcr = Database.convertLead(lc);
        System.assert(lcr.isSuccess());
        
        
        List<Case> lstCase = [Select id ,ContactId, Status, Type from Case where id =:c.id ];
        System.assert(lstCase.size() > 0 );
        System.assert(lstCase[0].ContactId !=null );
        System.assertEquals('Closed', lstCase[0].Status);
        System.assertEquals('Web Account Approved', lstCase[0].Type);
        
    }
}