• Yonathan Gottlieb
  • NEWBIE
  • 0 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 3
    Replies
Hello.

How ar eyou doing today?

Maybe you can try to help me with one issue. I have Apex Class - EmployeeMonthlyEmail, which takes collection of employees, and sends them emails. And another Test Apex Class - TestEmployeeMonthlyEmail for code coverage. Unfortunately, code coverage is 0%, and I am unable to understand why.

Please see code below. Based on test run results, situations with Good and Bad emails provided to a function are covered, and tests finish correctly returning True/False as expected. However, Code Coverage is at 0% and 0/27 lines.

Here is a screen shot with code coverage info and test run:
http://screencast.com/t/tWsfyHud

Please note that during debug execution, code works as expected and emails are received on GMail account. It means code is written corretly, but Code Coverage probably is done inappropriately.

Any ideas what is wrong in this situation?

p.s. TestDataFactory class works as expected - generates records, previously test code did not use DataFactory and code coverage was also 0%

------------ Apex Class EmployeeMonthlyEmail
public class EmployeeMonthlyEmail {
    public static Boolean sendEmailsToEmployees() {
        List<Employee__c> empList = 
            [SELECT Name, FirstName__c, LastName__c, Email__c
             FROM Employee__c
             WHERE Status__c != 'Disabled'
            ];
        
        for(Employee__c emp:empList){
            sendEmailToEmployee(emp);
        }
        
        return true;
    }
    
    public static Boolean sendEmailToEmployee(Employee__c emp){
        Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
        
        mail.setToAddresses(new String[]{emp.Email__c});
        mail.setReplyTo('name.surname@gmail.com');
        mail.setSenderDisplayName('Salesforce');
        mail.setSubject('Information about ' + emp.FirstName__c + ' ' + emp.LastName__c);
        mail.setBccSender(false);
        mail.setUseSignature(false);
        mail.setCharset('UTF-8');
        
        mail.setHtmlBody(
            '<p>Hello ' + emp.Name +',</p>'+
            '<p>Please check information we have, and let us know if we should update it.'+
            '<br />Thank you in advance ;)</p>'+
            '<p>First Name: '+ emp.FirstName__c + '<br />'+
            'Last Name: '+ emp.LastName__c + '</p>');
        
        try {
            List<Messaging.SendEmailResult> results = 
                Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
            
            if (!results.get(0).isSuccess()) {
                return false;
            } else {
                return true;
            }
        } catch (Exception e) {
            System.debug('Exception has occurred: ' + e.getMessage());
            return false;
        }
    }
}

------------ Test Apex Class EmployeeMonthlyEmail
@isTest
public class TestEmployeeMonthlyEmail {
    
    @isTest static void testSendEmailToEmployeeSuccess(){
        List<Employee__c> empList = TestDataFactory.createEmployees();
        Boolean result = EmployeeMonthlyEmail.sendEmailToEmployee(empList[0]);
        System.assertEquals(true,result);
    }
    
    @isTest static void testSendEmailToEmployeeFail(){
        List<Employee__c> empList = TestDataFactory.createEmployees();
        empList[0].Email__c = 'bademailname.com';
        Boolean result = EmployeeMonthlyEmail.sendEmailToEmployee(empList[0]);
        System.assertEquals(false,result);
    }
    
    @isTest static void testSendEmailsToEmployees(){
        List<Employee__c> empList = TestDataFactory.createEmployees();
        Boolean result = EmployeeMonthlyEmail.sendEmailsToEmployees();
        System.assertEquals(true,result);
    }
}
Operation: insert.Contact

By user/organization: 00520000000vb7q/00D200000000vUt

Caused the following Apex resource warnings:

Approaching limit for non-selective query against large object type (more than 100000 rows). Current size is approximately 76265 rows. When the limit is reached, the query will fail. Consider an indexed filter or contact salesforce.com about custom indexing.
Even if a field is indexed a filter might still not be selective when:
1. The filter value includes null (for instance binding with a list that contains null)
2. Data skew exists whereby the number of matching rows is very large (for instance, filtering for a particular foreign key value that occurs many times)
null
""Approaching limit for non-selective query against large object type (more than 100000 rows). Current size is approximately 76265 rows. When the limit is reached, the query will fail. Consider an indexed filter or contact salesforce.com about custom indexing.
Even if a field is indexed a filter might still not be selective when:
1. The filter value includes null (for instance binding with a list that contains null)
2. Data skew exists whereby the number of matching rows is very large (for instance, filtering for a particular foreign key value that occurs many times)""

now, what is going on here? and how to solve this?
 
  • October 15, 2015
  • Like
  • 0