• Akshay Reddy
  • 40 Points
  • Member since 2016

  • Chatter
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
  • 1
public class Task_triggerFunctions
    public static void sendEmailAlert(List<Task> Tasks) 
        List<Delivery_list_email__mdt> dls = [select label, email_id__c from Delivery_list_email__mdt];
        String[] options;
        List<String> sendTo = new List<String>();
            for (Task TaskRecord : Tasks) 
                if (TaskRecord.Send_email_alert__c != null && TaskRecord.Delivery_lists__c != null) 
                    EmailTemplate emailTemplate = [select Id, Subject, HtmlValue, Body from EmailTemplate where DeveloperName =: 'Task_alert'];
                    String subject = emailTemplate.Subject;
                    subject = subject.replace('{!Task.Subject}', TaskRecord.Subject);
                    String htmlBody = emailTemplate.HtmlValue;
                    htmlBody = htmlBody.replace('{!Task.Subject}', TaskRecord.Subject);
                    htmlBody = htmlBody.replace('{!Task.TaskSubtype}', TaskRecord.TaskSubtype);
                    String plainBody = emailTemplate.Body;
                    plainBody = plainBody.replace('{!Task.Subject}', TaskRecord.Subject);
                    plainBody = plainBody.replace('{!Task.TaskSubtype}', TaskRecord.TaskSubtype);
                    //Create an instance of SingleEmailMessage class
                    Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
                    List<Messaging.SingleEmailMessage> mails = new List<Messaging.SingleEmailMessage>();
                    //Subject of the email
                    mail.setSubject(System.Label.task_email_alert_subject + TaskRecord.Subject);
                    // Get the multi-picklist values to an array of Strings using split.            
                    options = TaskRecord.Delivery_lists__c.split(';');
                        //Get the Delivery list Email address from Custom Metadata and store them in the list(sendTo) 
                        for(String option : options)
                                for(Delivery_list_email__mdt dlss : dls)
                                    if( option == dlss.Label)
                    system.debug('mail ids' + sendTo);
                    //Add the 'to Addresses' we stored in the list (sendTo)
                    //Add the email to the master list
                    //Send all emails in the master list

I've written a class wherin the system will composed the email body using plaintext.replace. 

The main intention I've used the email template is that the admins should be able to edit the email template at any time and system should get the field values automatically. 

But in my logic I've to update both the email template and class as well.

but I want it to be more dynamic that whenever a new field is added in the email template, the class should get that new field automatically.

Could anyone help me here.
I'm trying to get through the service cloud superbadge, and challenge 3 is giving me this issue

"We can't find Entitlements on the Case Lightning Page. Ensure Entitlements are visible on Cases in Lightning."

I've got entitlements on the case record page, via the parent account, and I've got entitlements history via the parent Entitlement Name.. 

What is it actually looking for?