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
GMASJGMASJ 

Trigger is having 100% code coverage still not able to deploy

Hi,

  I have a below simple trigger  it has 100% code coverage
trigger updateopportunitycontact on Lead (before update) 
{
for(Lead lead:System.Trigger.new) 
{ 

  if (lead.IsConverted && lead.ConvertedOpportunityId != null ) 
 { 
   Contact con = [SELECT Id FROM Contact WHERE Contact.Id = :lead.ConvertedContactId];
    
   Opportunity opp = [SELECT Contact__c from Opportunity where opportunity.id = :lead.ConvertedOpportunityId];
   
   opp.Contact__c = lead.ConvertedContactId;
   
   update opp;
   
   
  }
  
}

}
Test Class 
@isTest(SeeAllData = true)
private class   test_updateopportunitycontact {

public static testmethod void testupdateoppcon()
{
test.startTest();
Lead testLead = new Lead(
   LastName='123456789890654',
   Company = 'Couchbase11',
   LeadSource = 'Training',
   run_assn_rules_yn__c = False
   
  );
  
 insert testLead;


Database.LeadConvert lc = new database.LeadConvert();

lc.setLeadId(testLead.id);

 
LeadStatus convertStatus = [Select Id, MasterLabel from LeadStatus where IsConverted=true limit 1];

lc.setConvertedStatus(convertStatus.MasterLabel);

Database.LeadConvertResult lcr = Database.convertLead(lc);

System.assert(lcr.isSuccess());

 
test.stopTest(); 
 
}

}

I keep getting below message when validated in production 

Code Coverage Failure
The following triggers have 0% code coverage. Each trigger must have at least 1% code coverage.
updateopportunitycontact


Please suggest me what might be the issue in the code. 

Thanks
Sudhir
 
Steven NsubugaSteven Nsubuga
I suspect other unrelated tests on production are failing. Run All tests before you attempt the validation of your change set. 
 
GMASJGMASJ
Thanks Steven but I am deploying only run specified test class which is working without any issue. but when deploying am getting this error. 

Thanks
 
Sohan Raj GuptaSohan Raj Gupta
Hi Sudir,

Make your Test Class as Public and try again.

Hope this will help you. Let me know if it helped or you need any more assistance. 

Please mark this is as the solution if it solved your purpose.

Thanks,
Sohan Raj Gupta 
GMASJGMASJ
Hi Sohan Raj, 

    I tried your suggestion it is still same not sure what the issue here 

Thanks
mukesh guptamukesh gupta
Hi Sudhir,

Make sure on production have below custom fields:-

IsConverted 
ConvertedOpportunityId
Contact__c 
ConvertedContactId


if you need any assistanse, Please let me know!!

Kindly mark my solution as the best answer if it helps you.

Thanks
Mukesh