You need to sign in to do that
Don't have an account?
Aafaque Hussain 10
Getting Error "the following triggers have 0% code coverage. Each trigger must have at least 1% code coverage." for trigger on Task Trigger
Can Anyone helps we I am trying to deploy below Task trigger from Sandbox to Production but getting error "the following triggers have 0% code coverage. Each trigger must have at least 1% code coverage."
In the below trigger I am trying to create update lead status to "Intro call" when a task is create with Subject contain "Intro call" this code work fine in sandbox but gives code coverage error while deployment.
I am new to devolopment /Coding
trigger changeLeadStatus on Task (before insert, before update) {
String desiredNewLeadStatus = 'Intro Call';
String myString;
List<Id> leadIds=new List<Id>();
for(Task t:trigger.new){
mystring=t.subject.toUpperCase();
if(t.Status=='Completed' && myString.contains('INTRO CALL')){
if(String.valueOf(t.whoId).startsWith('00Q')==TRUE){//check if the task is associated with a lead
leadIds.add(t.whoId);
}//if 2
}//if 1
}//for
List<Lead> leadsToUpdate=[SELECT Id, Status FROM Lead WHERE Id IN :leadIds AND IsConverted=FALSE];
For (Lead l:leadsToUpdate){
l.Status=desiredNewLeadStatus;
}//for
try{
update leadsToUpdate;
}catch(DMLException e){
system.debug('Leads were not all properly updated. Error: '+e);
}
}//trigger
In the below trigger I am trying to create update lead status to "Intro call" when a task is create with Subject contain "Intro call" this code work fine in sandbox but gives code coverage error while deployment.
I am new to devolopment /Coding
trigger changeLeadStatus on Task (before insert, before update) {
String desiredNewLeadStatus = 'Intro Call';
String myString;
List<Id> leadIds=new List<Id>();
for(Task t:trigger.new){
mystring=t.subject.toUpperCase();
if(t.Status=='Completed' && myString.contains('INTRO CALL')){
if(String.valueOf(t.whoId).startsWith('00Q')==TRUE){//check if the task is associated with a lead
leadIds.add(t.whoId);
}//if 2
}//if 1
}//for
List<Lead> leadsToUpdate=[SELECT Id, Status FROM Lead WHERE Id IN :leadIds AND IsConverted=FALSE];
For (Lead l:leadsToUpdate){
l.Status=desiredNewLeadStatus;
}//for
try{
update leadsToUpdate;
}catch(DMLException e){
system.debug('Leads were not all properly updated. Error: '+e);
}
}//trigger
From Salesforce: "Before you can deploy your code or package it for the Lightning Platform AppExchange, at least 75% of Apex code must be covered by tests, and all those tests must pass. In addition, each trigger must have some coverage."
Please see the trailhead below to learn about Unit Tests.
https://trailhead.salesforce.com/en/content/learn/modules/apex_testing/apex_testing_intro
Sample test class for your scenario something like this.