You need to sign in to do that
Don't have an account?
Gallery Integration
Email Notification when uploading Attachment on Task
Hi Everyone,
I have been trying to create an email notiication to task assignee upon a new attachment is uploaded to the task.
I created a checkbox field in activites called "Send_Attachment_Email__c".
If this checkbox is true, then a workflow to fire the email notification will be run.
However, I have a problem in the trigger to check the checkbox to true when an attachment is uploaded to task.
Can anybody help me?
I have been trying to create an email notiication to task assignee upon a new attachment is uploaded to the task.
I created a checkbox field in activites called "Send_Attachment_Email__c".
If this checkbox is true, then a workflow to fire the email notification will be run.
However, I have a problem in the trigger to check the checkbox to true when an attachment is uploaded to task.
Can anybody help me?
trigger attachmentTrig on Attachment (after insert) { // 1. Get List of Object Ids to notify on Set<Id> objectIds = new Set<Id>(); // 2. Loop through list of attachments on Task for(Attachment a:trigger.new){ String keyPrefix = a.ParentId; if(keyPrefix == 'Task'){ objectIds.add(a.ParentId); } } // 3. Set the Send Attachment Notification Email field to True if(objectIds.size() > 0){ List<Task> TaskList = [SELECT Id FROM Task WHERE Id IN :objectIds]; for(Task obj:TaskList){ obj.Send_Attachment_Email__c = true; } if(TaskList.size() > 0){ update TaskList; } } }
Use this code:
Let me know if it helps
Thanks!
Thanks for your help.
I have tried the code you gave (changing the if to '00T').
However it still dont work.
The checkbox is still not checked when a file is uploaded on task.
Finally after a lot of digging, I managed to find a solution:
First create this class in your org.
Now, delete/deactivate the attachment trigger which you had created earlier.
And now create a trigger on Task object as follows:
I will explain why and what about the code, but let's first get your requirement fulfilled.
Really Appreciate your help here.
However, after trying your code, the send_attachment_email__c checkbox is also not checked even after i uploaded the attachment on task.
Did you deactivate the attachment trigger?
Also, what i would like to know is from where are you adding the attachment to the task. Please share the screenshot.
Yes I already deactivate the trigger on attachment,
Here is the screenshot on where I upload the attachment: