• Elmer Uytingco
  • NEWBIE
  • 5 Points
  • Member since 2015
  • IT Enterprise/Solution Architect

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 4
    Replies

Unable to receive email from Email Manager in exercise although the log below indicates email was sent succesfully.  Any ideas on how to troubleshoot?

Here is the code also:

public class EmailManager {

    // Public method
    public static void sendMail(String address, String subject, String body) {
        // Create an email message object
        Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
        String[] toAddresses = new String[] {address};
        mail.setToAddresses(toAddresses);
        mail.setSubject(subject);
        mail.setPlainTextBody(body);
        // Pass this email message to the built-in sendEmail method
        // of the Messaging class
        Messaging.SendEmailResult[] results = Messaging.sendEmail(
                                 new Messaging.SingleEmailMessage[] { mail });
       
        // Call a helper method to inspect the returned results
        inspectResults(results);
    }
   
    // Helper method
    private static Boolean inspectResults(Messaging.SendEmailResult[] results) {
        Boolean sendResult = true;
       
        // sendEmail returns an array of result objects.
        // Iterate through the list to inspect results.
        // In this class, the methods send only one email,
        // so we should have only one result.
        for (Messaging.SendEmailResult res : results) {
            if (res.isSuccess()) {
                System.debug('Email sent successfully');
            }
            else {
                sendResult = false;
                System.debug('The following errors occurred: ' + res.getErrors());                
            }
        }
       
        return sendResult;
    }

}

LOG:
====
37.0 APEX_CODE,FINEST;APEX_PROFILING,INFO;CALLOUT,INFO;DB,INFO;SYSTEM,DEBUG;VALIDATION,INFO;VISUALFORCE,INFO;WORKFLOW,INFO
Execute Anonymous: //EmailManager em = new EmailManager();
Execute Anonymous: EmailManager.sendMail('uytingcoel@gmail.com', 'Trailhead Tutorial', '123 body');
08:12:27.1 (1693955)|USER_INFO|[EXTERNAL]|005610000010YwX|uytingcoel@yahoo.com|Eastern Standard Time|GMT-04:00
08:12:27.1 (1721463)|EXECUTION_STARTED
08:12:27.1 (1730849)|CODE_UNIT_STARTED|[EXTERNAL]|execute_anonymous_apex
08:12:27.1 (2046370)|HEAP_ALLOCATE|[72]|Bytes:3
08:12:27.1 (2124668)|HEAP_ALLOCATE|[77]|Bytes:152
08:12:27.1 (2168187)|HEAP_ALLOCATE|[342]|Bytes:408
08:12:27.1 (2194894)|HEAP_ALLOCATE|[355]|Bytes:408
08:12:27.1 (2216264)|HEAP_ALLOCATE|[467]|Bytes:48
08:12:27.1 (2253417)|HEAP_ALLOCATE|[139]|Bytes:6
08:12:27.1 (2285536)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:1
08:12:27.1 (2398403)|STATEMENT_EXECUTE|[1]
08:12:27.1 (2402986)|STATEMENT_EXECUTE|[2]
08:12:27.1 (2407023)|HEAP_ALLOCATE|[2]|Bytes:20
08:12:27.1 (2410857)|HEAP_ALLOCATE|[2]|Bytes:18
08:12:27.1 (2413144)|HEAP_ALLOCATE|[2]|Bytes:8
08:12:27.1 (2478268)|HEAP_ALLOCATE|[50]|Bytes:5
08:12:27.1 (2505766)|HEAP_ALLOCATE|[56]|Bytes:5
08:12:27.1 (2515779)|HEAP_ALLOCATE|[64]|Bytes:7
08:12:27.1 (2546886)|SYSTEM_MODE_ENTER|false
08:12:27.1 (2584411)|HEAP_ALLOCATE|[2]|Bytes:5
08:12:27.1 (3957848)|HEAP_ALLOCATE|[2]|Bytes:4
08:12:27.1 (3964998)|HEAP_ALLOCATE|[2]|Bytes:5
08:12:27.1 (3988092)|METHOD_ENTRY|[1]|01p610000089QAq|EmailManager.EmailManager()
08:12:27.1 (3996337)|STATEMENT_EXECUTE|[1]
08:12:27.1 (4004467)|STATEMENT_EXECUTE|[1]
08:12:27.1 (4013806)|METHOD_EXIT|[1]|EmailManager
08:12:27.1 (4055378)|METHOD_ENTRY|[2]|01p610000089QAq|EmailManager.sendMail(String, String, String)
08:12:27.1 (4090284)|VARIABLE_SCOPE_BEGIN|[4]|address|String|false|false
08:12:27.1 (4122577)|VARIABLE_ASSIGNMENT|[4]|address|"uytingcoel@gmail.com"
08:12:27.1 (4133343)|VARIABLE_SCOPE_BEGIN|[4]|subject|String|false|false
08:12:27.1 (4137861)|VARIABLE_ASSIGNMENT|[4]|subject|"Trailhead Tutorial"
08:12:27.1 (4140882)|VARIABLE_SCOPE_BEGIN|[4]|body|String|false|false
08:12:27.1 (4144239)|VARIABLE_ASSIGNMENT|[4]|body|"123 body"
08:12:27.1 (4155079)|STATEMENT_EXECUTE|[4]
08:12:27.1 (4157138)|STATEMENT_EXECUTE|[6]
08:12:27.1 (4247692)|VARIABLE_SCOPE_BEGIN|[6]|mail|Messaging.SingleEmailMessage|true|false
08:12:27.1 (4362488)|VARIABLE_ASSIGNMENT|[6]|mail|"common.api.soap.wsdl.SingleEmailMessage@efa978"|0x943ea19
08:12:27.1 (4369535)|STATEMENT_EXECUTE|[7]
08:12:27.1 (4411988)|HEAP_ALLOCATE|[7]|Bytes:4
08:12:27.1 (4487206)|VARIABLE_SCOPE_BEGIN|[7]|toAddresses|List<String>|true|false
08:12:27.1 (4523565)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:8
08:12:27.1 (4550008)|VARIABLE_ASSIGNMENT|[7]|toAddresses|{"s":1,"v":["uytingcoel@gmail.com"]}|0x1cd2b297
08:12:27.1 (4555391)|STATEMENT_EXECUTE|[8]
08:12:27.1 (4610574)|STATEMENT_EXECUTE|[9]
08:12:27.1 (4658050)|STATEMENT_EXECUTE|[10]
08:12:27.1 (4679999)|STATEMENT_EXECUTE|[13]
08:12:27.1 (4704696)|HEAP_ALLOCATE|[14]|Bytes:4
08:12:27.1 (4827799)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:8
08:12:27.1 (4882464)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:8
08:12:27.1 (74154700)|EMAIL_QUEUE|[13]|subject: Trailhead Tutorial, bccSender: false, saveAsActivity: true, useSignature: true, toAddresses: [uytingcoel@gmail.com], plainTextBody: 123 body,
08:12:27.1 (74280802)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:8
08:12:27.1 (74335953)|HEAP_ALLOCATE|[13]|Bytes:8
08:12:27.1 (74371094)|VARIABLE_SCOPE_BEGIN|[13]|results|List<Messaging.SendEmailResult>|true|false
08:12:27.1 (74490967)|VARIABLE_ASSIGNMENT|[13]|results|"common.apex.runtime.impl.ScalarList@762a45b4"|0x2174fb9
08:12:27.1 (74504199)|STATEMENT_EXECUTE|[17]
08:12:27.1 (74542513)|METHOD_ENTRY|[17]|01p610000089QAq|EmailManager.inspectResults(List<Messaging.SendEmailResult>)
08:12:27.1 (74583048)|VARIABLE_SCOPE_BEGIN|[21]|results|List<Messaging.SendEmailResult>|true|false
08:12:27.1 (74645265)|VARIABLE_ASSIGNMENT|[21]|results|"common.apex.runtime.impl.ScalarList@762a45b4"|0x2174fb9
08:12:27.1 (74655397)|STATEMENT_EXECUTE|[21]
08:12:27.1 (74657423)|STATEMENT_EXECUTE|[22]
08:12:27.1 (74668379)|VARIABLE_SCOPE_BEGIN|[22]|sendResult|Boolean|false|false
08:12:27.1 (74678513)|HEAP_ALLOCATE|[22]|Bytes:5
08:12:27.1 (74685915)|VARIABLE_ASSIGNMENT|[22]|sendResult|true
08:12:27.1 (74984390)|HEAP_ALLOCATE|[28]|Bytes:5
08:12:27.1 (75155948)|HEAP_ALLOCATE|[28]|Bytes:4
08:12:27.1 (75194225)|VARIABLE_SCOPE_BEGIN|[28]|res|Messaging.SendEmailResult|true|false
08:12:27.1 (75250996)|VARIABLE_ASSIGNMENT|[28]|res|"common.api.soap.wsdl.SendEmailResult@762a4595"|0x16972a5
08:12:27.1 (75258727)|STATEMENT_EXECUTE|[28]
08:12:27.1 (75296793)|STATEMENT_EXECUTE|[29]
08:12:27.1 (75299001)|STATEMENT_EXECUTE|[30]
08:12:27.1 (75305905)|HEAP_ALLOCATE|[30]|Bytes:23
08:12:27.1 (75358958)|USER_DEBUG|[30]|DEBUG|Email sent successfully
08:12:27.1 (75377076)|HEAP_ALLOCATE|[28]|Bytes:5
08:12:27.1 (75390882)|VARIABLE_ASSIGNMENT|[28]|res|null|
08:12:27.1 (75395724)|STATEMENT_EXECUTE|[38]
08:12:27.1 (75401673)|METHOD_EXIT|[17]|01p610000089QAq|EmailManager.inspectResults(List<Messaging.SendEmailResult>)
08:12:27.1 (75410404)|METHOD_EXIT|[2]|01p610000089QAq|EmailManager.sendMail(String, String, String)
08:12:27.1 (75423531)|SYSTEM_MODE_EXIT|false
08:12:27.95 (95395610)|CUMULATIVE_LIMIT_USAGE
08:12:27.95 (95395610)|LIMIT_USAGE_FOR_NS|(default)|
  Number of SOQL queries: 0 out of 100
  Number of query rows: 0 out of 50000
  Number of SOSL queries: 0 out of 20
  Number of DML statements: 0 out of 150
  Number of DML rows: 0 out of 10000
  Maximum CPU time: 0 out of 10000
  Maximum heap size: 0 out of 6000000
  Number of callouts: 0 out of 100
  Number of Email Invocations: 1 out of 10
  Number of future calls: 0 out of 50
  Number of queueable jobs added to the queue: 0 out of 50
  Number of Mobile Apex push calls: 0 out of 10

08:12:27.95 (95395610)|CUMULATIVE_LIMIT_USAGE_END

08:12:27.1 (95471081)|CODE_UNIT_FINISHED|execute_anonymous_apex
08:12:27.1 (96992487)|EXECUTION_FINISHED
 
Getting the following Error:

Challenge not yet complete... here's what's wrong:
The 'Days_Since_Last_Update__c' formula field did not return the correct number of days between an Account’s Last Activity Date and today

Unable to receive email from Email Manager in exercise although the log below indicates email was sent succesfully.  Any ideas on how to troubleshoot?

Here is the code also:

public class EmailManager {

    // Public method
    public static void sendMail(String address, String subject, String body) {
        // Create an email message object
        Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
        String[] toAddresses = new String[] {address};
        mail.setToAddresses(toAddresses);
        mail.setSubject(subject);
        mail.setPlainTextBody(body);
        // Pass this email message to the built-in sendEmail method
        // of the Messaging class
        Messaging.SendEmailResult[] results = Messaging.sendEmail(
                                 new Messaging.SingleEmailMessage[] { mail });
       
        // Call a helper method to inspect the returned results
        inspectResults(results);
    }
   
    // Helper method
    private static Boolean inspectResults(Messaging.SendEmailResult[] results) {
        Boolean sendResult = true;
       
        // sendEmail returns an array of result objects.
        // Iterate through the list to inspect results.
        // In this class, the methods send only one email,
        // so we should have only one result.
        for (Messaging.SendEmailResult res : results) {
            if (res.isSuccess()) {
                System.debug('Email sent successfully');
            }
            else {
                sendResult = false;
                System.debug('The following errors occurred: ' + res.getErrors());                
            }
        }
       
        return sendResult;
    }

}

LOG:
====
37.0 APEX_CODE,FINEST;APEX_PROFILING,INFO;CALLOUT,INFO;DB,INFO;SYSTEM,DEBUG;VALIDATION,INFO;VISUALFORCE,INFO;WORKFLOW,INFO
Execute Anonymous: //EmailManager em = new EmailManager();
Execute Anonymous: EmailManager.sendMail('uytingcoel@gmail.com', 'Trailhead Tutorial', '123 body');
08:12:27.1 (1693955)|USER_INFO|[EXTERNAL]|005610000010YwX|uytingcoel@yahoo.com|Eastern Standard Time|GMT-04:00
08:12:27.1 (1721463)|EXECUTION_STARTED
08:12:27.1 (1730849)|CODE_UNIT_STARTED|[EXTERNAL]|execute_anonymous_apex
08:12:27.1 (2046370)|HEAP_ALLOCATE|[72]|Bytes:3
08:12:27.1 (2124668)|HEAP_ALLOCATE|[77]|Bytes:152
08:12:27.1 (2168187)|HEAP_ALLOCATE|[342]|Bytes:408
08:12:27.1 (2194894)|HEAP_ALLOCATE|[355]|Bytes:408
08:12:27.1 (2216264)|HEAP_ALLOCATE|[467]|Bytes:48
08:12:27.1 (2253417)|HEAP_ALLOCATE|[139]|Bytes:6
08:12:27.1 (2285536)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:1
08:12:27.1 (2398403)|STATEMENT_EXECUTE|[1]
08:12:27.1 (2402986)|STATEMENT_EXECUTE|[2]
08:12:27.1 (2407023)|HEAP_ALLOCATE|[2]|Bytes:20
08:12:27.1 (2410857)|HEAP_ALLOCATE|[2]|Bytes:18
08:12:27.1 (2413144)|HEAP_ALLOCATE|[2]|Bytes:8
08:12:27.1 (2478268)|HEAP_ALLOCATE|[50]|Bytes:5
08:12:27.1 (2505766)|HEAP_ALLOCATE|[56]|Bytes:5
08:12:27.1 (2515779)|HEAP_ALLOCATE|[64]|Bytes:7
08:12:27.1 (2546886)|SYSTEM_MODE_ENTER|false
08:12:27.1 (2584411)|HEAP_ALLOCATE|[2]|Bytes:5
08:12:27.1 (3957848)|HEAP_ALLOCATE|[2]|Bytes:4
08:12:27.1 (3964998)|HEAP_ALLOCATE|[2]|Bytes:5
08:12:27.1 (3988092)|METHOD_ENTRY|[1]|01p610000089QAq|EmailManager.EmailManager()
08:12:27.1 (3996337)|STATEMENT_EXECUTE|[1]
08:12:27.1 (4004467)|STATEMENT_EXECUTE|[1]
08:12:27.1 (4013806)|METHOD_EXIT|[1]|EmailManager
08:12:27.1 (4055378)|METHOD_ENTRY|[2]|01p610000089QAq|EmailManager.sendMail(String, String, String)
08:12:27.1 (4090284)|VARIABLE_SCOPE_BEGIN|[4]|address|String|false|false
08:12:27.1 (4122577)|VARIABLE_ASSIGNMENT|[4]|address|"uytingcoel@gmail.com"
08:12:27.1 (4133343)|VARIABLE_SCOPE_BEGIN|[4]|subject|String|false|false
08:12:27.1 (4137861)|VARIABLE_ASSIGNMENT|[4]|subject|"Trailhead Tutorial"
08:12:27.1 (4140882)|VARIABLE_SCOPE_BEGIN|[4]|body|String|false|false
08:12:27.1 (4144239)|VARIABLE_ASSIGNMENT|[4]|body|"123 body"
08:12:27.1 (4155079)|STATEMENT_EXECUTE|[4]
08:12:27.1 (4157138)|STATEMENT_EXECUTE|[6]
08:12:27.1 (4247692)|VARIABLE_SCOPE_BEGIN|[6]|mail|Messaging.SingleEmailMessage|true|false
08:12:27.1 (4362488)|VARIABLE_ASSIGNMENT|[6]|mail|"common.api.soap.wsdl.SingleEmailMessage@efa978"|0x943ea19
08:12:27.1 (4369535)|STATEMENT_EXECUTE|[7]
08:12:27.1 (4411988)|HEAP_ALLOCATE|[7]|Bytes:4
08:12:27.1 (4487206)|VARIABLE_SCOPE_BEGIN|[7]|toAddresses|List<String>|true|false
08:12:27.1 (4523565)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:8
08:12:27.1 (4550008)|VARIABLE_ASSIGNMENT|[7]|toAddresses|{"s":1,"v":["uytingcoel@gmail.com"]}|0x1cd2b297
08:12:27.1 (4555391)|STATEMENT_EXECUTE|[8]
08:12:27.1 (4610574)|STATEMENT_EXECUTE|[9]
08:12:27.1 (4658050)|STATEMENT_EXECUTE|[10]
08:12:27.1 (4679999)|STATEMENT_EXECUTE|[13]
08:12:27.1 (4704696)|HEAP_ALLOCATE|[14]|Bytes:4
08:12:27.1 (4827799)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:8
08:12:27.1 (4882464)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:8
08:12:27.1 (74154700)|EMAIL_QUEUE|[13]|subject: Trailhead Tutorial, bccSender: false, saveAsActivity: true, useSignature: true, toAddresses: [uytingcoel@gmail.com], plainTextBody: 123 body,
08:12:27.1 (74280802)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:8
08:12:27.1 (74335953)|HEAP_ALLOCATE|[13]|Bytes:8
08:12:27.1 (74371094)|VARIABLE_SCOPE_BEGIN|[13]|results|List<Messaging.SendEmailResult>|true|false
08:12:27.1 (74490967)|VARIABLE_ASSIGNMENT|[13]|results|"common.apex.runtime.impl.ScalarList@762a45b4"|0x2174fb9
08:12:27.1 (74504199)|STATEMENT_EXECUTE|[17]
08:12:27.1 (74542513)|METHOD_ENTRY|[17]|01p610000089QAq|EmailManager.inspectResults(List<Messaging.SendEmailResult>)
08:12:27.1 (74583048)|VARIABLE_SCOPE_BEGIN|[21]|results|List<Messaging.SendEmailResult>|true|false
08:12:27.1 (74645265)|VARIABLE_ASSIGNMENT|[21]|results|"common.apex.runtime.impl.ScalarList@762a45b4"|0x2174fb9
08:12:27.1 (74655397)|STATEMENT_EXECUTE|[21]
08:12:27.1 (74657423)|STATEMENT_EXECUTE|[22]
08:12:27.1 (74668379)|VARIABLE_SCOPE_BEGIN|[22]|sendResult|Boolean|false|false
08:12:27.1 (74678513)|HEAP_ALLOCATE|[22]|Bytes:5
08:12:27.1 (74685915)|VARIABLE_ASSIGNMENT|[22]|sendResult|true
08:12:27.1 (74984390)|HEAP_ALLOCATE|[28]|Bytes:5
08:12:27.1 (75155948)|HEAP_ALLOCATE|[28]|Bytes:4
08:12:27.1 (75194225)|VARIABLE_SCOPE_BEGIN|[28]|res|Messaging.SendEmailResult|true|false
08:12:27.1 (75250996)|VARIABLE_ASSIGNMENT|[28]|res|"common.api.soap.wsdl.SendEmailResult@762a4595"|0x16972a5
08:12:27.1 (75258727)|STATEMENT_EXECUTE|[28]
08:12:27.1 (75296793)|STATEMENT_EXECUTE|[29]
08:12:27.1 (75299001)|STATEMENT_EXECUTE|[30]
08:12:27.1 (75305905)|HEAP_ALLOCATE|[30]|Bytes:23
08:12:27.1 (75358958)|USER_DEBUG|[30]|DEBUG|Email sent successfully
08:12:27.1 (75377076)|HEAP_ALLOCATE|[28]|Bytes:5
08:12:27.1 (75390882)|VARIABLE_ASSIGNMENT|[28]|res|null|
08:12:27.1 (75395724)|STATEMENT_EXECUTE|[38]
08:12:27.1 (75401673)|METHOD_EXIT|[17]|01p610000089QAq|EmailManager.inspectResults(List<Messaging.SendEmailResult>)
08:12:27.1 (75410404)|METHOD_EXIT|[2]|01p610000089QAq|EmailManager.sendMail(String, String, String)
08:12:27.1 (75423531)|SYSTEM_MODE_EXIT|false
08:12:27.95 (95395610)|CUMULATIVE_LIMIT_USAGE
08:12:27.95 (95395610)|LIMIT_USAGE_FOR_NS|(default)|
  Number of SOQL queries: 0 out of 100
  Number of query rows: 0 out of 50000
  Number of SOSL queries: 0 out of 20
  Number of DML statements: 0 out of 150
  Number of DML rows: 0 out of 10000
  Maximum CPU time: 0 out of 10000
  Maximum heap size: 0 out of 6000000
  Number of callouts: 0 out of 100
  Number of Email Invocations: 1 out of 10
  Number of future calls: 0 out of 50
  Number of queueable jobs added to the queue: 0 out of 50
  Number of Mobile Apex push calls: 0 out of 10

08:12:27.95 (95395610)|CUMULATIVE_LIMIT_USAGE_END

08:12:27.1 (95471081)|CODE_UNIT_FINISHED|execute_anonymous_apex
08:12:27.1 (96992487)|EXECUTION_FINISHED
 
Getting the following Error:

Challenge not yet complete... here's what's wrong:
The 'Days_Since_Last_Update__c' formula field did not return the correct number of days between an Account’s Last Activity Date and today