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
Christopher Littlefield 6Christopher Littlefield 6 

How do I increase code coverage for this Apex Trigger

I believe I need a test for the following trigger that I am trying to deactivate, but my code coverage is too low.  I'm desperate at this point because it is holding up an install.

trigger ConvertLeadToContact on Lead (after update) {
//cbl code to comment the trigger code 1/26- add this line and line below
/*
  
  List<Lead> leadsToConvert = new list<Lead>();
  for(Lead l: Trigger.new){
    if(l.Program__c == 'SPHP')
      if(!l.isConverted)
        leadsToConvert.add(l);
  }
  
  Id acctId = null;
  List<Account> acctList = [
    SELECT Id 
    FROM Account 
    WHERE Name = 'CGPS Bucket' AND Program_Email__c = 'owladmissions@une.edu'
  ];
  if (acctList.size() == 1)
    acctId = acctList[0].Id;

  LeadStatus convertStatus = [
    SELECT Id, 
    MasterLabel 
    FROM LeadStatus 
    WHERE IsConverted = true 
    LIMIT 1
  ];

  List<Database.LeadConvert> leadConverts = new list<Database.LeadConvert>();
  for(Lead l : leadsToConvert){
    Database.LeadConvert lc = new database.LeadConvert();
    lc.setLeadId(l.Id);
    lc.setConvertedStatus(convertStatus.MasterLabel);
    lc.setDoNotCreateOpportunity(true);
    lc.setAccountId(acctId);
    leadConverts.add(lc);
  }

  if(!leadConverts.isEmpty()){ 
    Database.LeadConvertResult[] lcrList = Database.convertLead(leadConverts, false);
    for(Database.LeadConvertResult lcr : lcrList)
      System.assert(lcr.isSuccess());
  }
 */
 //End of comment line code - add this line and also the line above which has */
}
Raj VakatiRaj Vakati
@IsTest
private class LeadConvert{
    private static testMethod void myUnitTest() {
        
        Account a = new Account() ;
        a.Name = 'CGPS Bucket';
        a.Program_Email__c = 'owladmissions@une.edu' ;
        insert a ;
        LeadStatus convertStatus = [Select Id, MasterLabel from LeadStatus where IsConverted=true limit 1];
        Lead lead=new Lead(LastName='Doe',FirstName='John',Company='Test',Status='Open - Not Contacted'  ,Program__c='SPHP' , isConverted =false);
        insert lead;                
        Database.LeadConvert lc = new database.LeadConvert();
        lc.setLeadId(lead.id);
        lc.setAccountId(a.id);
        lc.setConvertedStatus(convertStatus.MasterLabel);
        Database.LeadConvertResult lcr = Database.convertLead(lc);
        
        
        System.assert(lcr.isSuccess());
        
        
        
        
    }
}

 
Christopher Littlefield 6Christopher Littlefield 6
Thanks, @RajV.