• Dnyaneshwar Mandwade 9
  • NEWBIE
  • 0 Points
  • Member since 2020

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies
Hey I'm really new to Salesforce development. I have two triggers i need to deploy from sandbox, but code coverage is 0%.
I have to add some test classes, right? but i'm not sure how to handle it.

Trigger 1
trigger CopyPartnerSource on Lead (before insert, before update) {

for (Lead l : Trigger.new) { l.Partner_Account_Mirror__c = l.Partner_Account__c; } }




Trigger 2
trigger Trigger_Task_Send_Email on Task (before update) {
  
    Set<Id> createdbyIds = new Set<Id>();
   
    for(Task tsk: Trigger.New)
        createdbyIds.add(tsk.createdbyId);
   
    Map<Id, User> userMap = new Map<Id,User>([select Name, Email from User where Id in :createdbyIds]);
    for(Task tsk : Trigger.New)
    {
        User theUser = userMap.get(tsk.createdbyId);
        Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
        String[] toAddresses = new String[] {theUser.Email};
        mail.setToAddresses(toAddresses);    // Set the TO addresses
        mail.setSubject('A task created by you has been updated');    // Set the subject
  
        String template = 'Hello {0}, \nYour task has been modified. Here are the details: \n\n';
        template+= 'Subject - {1}\n';
        template+= 'Due Date - {2}\n';
        String duedate = '';
        if (tsk.ActivityDate==null)
            duedate = '';
        else
            duedate = tsk.ActivityDate.format();
        List<String> args = new List<String>();
        args.add(theUser.Name);
        args.add(tsk.Subject);
        args.add(duedate);
        
       
        // Here's the String.format() call.
        String formattedHtml = String.format(template, args);
       
        mail.setPlainTextBody(formattedHtml);
        Messaging.SendEmail(new Messaging.SingleEmailMessage[] {mail});
    }
}




Any help will be appreciated, thanks