• Elle Benami
  • NEWBIE
  • 0 Points
  • Member since 2020

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies
This feature would have many uses, but my current use case is as follows:

The Daily Digest is a locked Chatter template displaying the feed of that day. I want to create an email template with that same look and feel, but for displaying all open tasks (regardless of when they were created/updated) of the recipient.

Look forward to hearing any suggestions you have!

All,
I'm writing a trigger to send an email notification to our Internal Owner (a custom field - Internal_Owner__c) of the Contact if a User chooses the Type 'Inbound Queue'. I'm unsure how to:
1.) Add in the SOQL 'Where Task.Type = 'Inbound Queue'.
2.) Send the notification to our Internal Owner of the Contact instead of whom the task is assigned to. Not sure if I need to create a formula field.

Here is my code thus far:

trigger LogACall_Send_Email on Task (before insert) {
    Set<Id> ownerIds = new Set<Id>();
    
    for(Task tsk: Trigger.New)
        ownerIds.add(tsk.ownerId);

    Map<Id, User> userMap = new Map<Id,User>([select Name, Email from User where Id in :ownerIds]);
    for(Task tsk : Trigger.New) {
        User theUser = userMap.get(tsk.ownerId);
        Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
        String[] toAddresses = new String[] {theUser.Email};
        mail.setToAddresses(toAddresses);
        mail.setSubject('Inbound Queue Call');
        String template = 'Hello {0}, \n\nAn Inbound Queue call was taken for you. Here are the details. \n\n';
        template+= 'Subject - {1}\n';
        template+= 'Due Date - {2}\n';
        template+= 'Type - {3}\n';
        template+= 'Comments - {4}\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);
        args.add(tsk.type);
        args.add(tsk.Description);

        String formattedHtml = String.format(template, args);
       
        mail.setPlainTextBody(formattedHtml);
        Messaging.SendEmail(new Messaging.SingleEmailMessage[] {mail});
    }
}