• Aafaque Hussain 10
  • NEWBIE
  • 0 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 0
    Replies
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