• Christian Øelund
  • NEWBIE
  • 10 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 17
    Replies
Hey I'm really new to coding
Then i run the test class, it gived me this error;


<span unselectable="on" "="" style="display: block; padding: 3px 4px; overflow: hidden; margin-left: 0px; color: rgb(34, 34, 34); font-family: Arial, Helvetica, sans-serif; font-size: 12px; line-height: normal; white-space: nowrap; widows: 1; background-color: rgb(218, 240, 249);">Stack Trace
Class.Trigger_Task_Send_Email_Test1.emailTest_single: line 15, column 1

My trigger
trigger Trigger_Task_Send_Email on Task (before update) {
    // Don't forget this- all triggers in SF are bulk triggers and so
    // they can fire on multiple objects. So you need to process objects
    // in a FOR loop.
    Set<Id> createdbyIds = new Set<Id>();
   
    for(Task tsk: Trigger.New)
        createdbyIds.add(tsk.createdbyId);
   
    // Build a map of all users who are assigned the tasks.
    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
        // Next, create a string template. Specify {0}, {1} etc. in place of actual values.
        // You can replace these values with a call to String.Format.
        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});
    }
}

My test class (gived me 96% code coverage, but makes the above error)
@isTest
private class Trigger_Task_Send_Email_Test1 {
    static testMethod void emailTest_single() {
        Task testTask = new Task(
            Subject = 'Test Task 1',
            ActivityDate = Date.today()
        );
        insert testTask;

        Integer emailsSentPre = Limits.getEmailInvocations();

        Test.startTest();

        testTask.Subject = 'Test Task 2';
        update testTask;

        Test.stopTest();

        Integer emailsSentPost = Limits.getEmailInvocations();
        Integer emailsSent = emailsSentPost - emailsSentPre;

        System.assertEquals(1, emailsSent, 'We should have only sent one email');
    }
}

Their must be an error en my test class, but can't figure out what. Can somebody help me please.

Thanks
 
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
Hey I'm really new to coding
Then i run the test class, it gived me this error;


<span unselectable="on" "="" style="display: block; padding: 3px 4px; overflow: hidden; margin-left: 0px; color: rgb(34, 34, 34); font-family: Arial, Helvetica, sans-serif; font-size: 12px; line-height: normal; white-space: nowrap; widows: 1; background-color: rgb(218, 240, 249);">Stack Trace
Class.Trigger_Task_Send_Email_Test1.emailTest_single: line 15, column 1

My trigger
trigger Trigger_Task_Send_Email on Task (before update) {
    // Don't forget this- all triggers in SF are bulk triggers and so
    // they can fire on multiple objects. So you need to process objects
    // in a FOR loop.
    Set<Id> createdbyIds = new Set<Id>();
   
    for(Task tsk: Trigger.New)
        createdbyIds.add(tsk.createdbyId);
   
    // Build a map of all users who are assigned the tasks.
    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
        // Next, create a string template. Specify {0}, {1} etc. in place of actual values.
        // You can replace these values with a call to String.Format.
        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});
    }
}

My test class (gived me 96% code coverage, but makes the above error)
@isTest
private class Trigger_Task_Send_Email_Test1 {
    static testMethod void emailTest_single() {
        Task testTask = new Task(
            Subject = 'Test Task 1',
            ActivityDate = Date.today()
        );
        insert testTask;

        Integer emailsSentPre = Limits.getEmailInvocations();

        Test.startTest();

        testTask.Subject = 'Test Task 2';
        update testTask;

        Test.stopTest();

        Integer emailsSentPost = Limits.getEmailInvocations();
        Integer emailsSent = emailsSentPost - emailsSentPre;

        System.assertEquals(1, emailsSent, 'We should have only sent one email');
    }
}

Their must be an error en my test class, but can't figure out what. Can somebody help me please.

Thanks
 
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