• Kalaivani Subbaiyan
  • NEWBIE
  • 0 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 2
    Replies
On exploring a topic of “Get Started with Apex Triggers->Calling a Class Method from a Trigger” and found an issue in email send. The reference URL is https://trailhead.salesforce.com/en/content/learn/modules/apex_triggers/apex_triggers_intro (https://nam03.safelinks.protection.outlook.com/?url=https%3A%2F%2Ftrailhead.salesforce.com%2Fen%2Fcontent%2Flearn%2Fmodules%2Fapex_triggers%2Fapex_triggers_intro&data=02%7C01%7CKalaivani.S%40academicpartnerships.com%7C9e204f268e8b413df08608d7c04ddbfa%7C8720e8557e2849ffa1a78d5e66b5659e%7C0%7C0%7C637189312958883426&sdata=y%2B6TkKarjuWhyCLT02pFMYwzrz6VLqJVB4t4PYF2NuQ%3D&reserved=0" originalsrc="https://trailhead.salesforce.com/en/content/learn/modules/apex_triggers/apex_triggers_intro" shash="r6IJIGnrjYA3GYR7WD6J0bypX1qlO/SqUeK3B5A/yjISYc0quYEpLBnH+E1ZCXuTIV3rlfxVylGduUA0VJ5KDYM0OheVncq/uPGWlwaKa8jxE6RmxJ0ulqAfX7YCtWxIBMSZH14DFcGsnVHAvO/IjFFCivGsuOFVBaC/H5QFEzQ=" style="color:#0563c1; text-decoration:underline). Log says, email sending is successful however email didn’t triggered.
Used code is,
trigger ExampleTrigger on Contact (after insert, after delete) {
    if (Trigger.isInsert) {
        Integer recordCount = Trigger.New.size();
        // Call a utility method from another class
        EmailManager.sendMail(xyz@zax.com', 'Trailhead Trigger Tutorial', 
                    recordCount + ' contact(s) were inserted.');
    }
    else if (Trigger.isDelete) {
        // Process after delete
    }
}
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());                
            }
        }
       System.debug('sendResult =' + sendResult);
        return sendResult;
    }
}

In Setup->Deliverabilty- > All Emails. Still not triggering the email.



 
I need move variables to a file and use it in apex classes. How do this?
Account acc0 = new account(name="acme");
Insert acc;
Account acc1 = acc0.clone();
insert acc1;
System.debug(acc1.getCloneSourceId()); //Producing expected result as the record(Acc1) is in runtime memory
Account acc2 = [select id from account where id =: acc1.id];
system.debug(acc2.getCloneSourceId());//Is producing null value, as the record is retrieved from database

How to get the Clone Id of a record coming from the database?