You need to sign in to do that
Don't have an account?
SF_Admin96
Sending Email Alert when a new Attachment is added
Hi Experts,
I know that this is not a standard functionality. However, can anyone share a sample code for sending email alert when a new attachment has been added to the custom object.
Here is the specific scenario:
When a new file or multiple files has been added for a custom object, I would like a specific set of users to be notified.
Any assistance is greatly appreciated. Thanks.
I know that this is not a standard functionality. However, can anyone share a sample code for sending email alert when a new attachment has been added to the custom object.
Here is the specific scenario:
When a new file or multiple files has been added for a custom object, I would like a specific set of users to be notified.
Any assistance is greatly appreciated. Thanks.
So here is your design pattern:
-
Create a checkbox field on your object called Send Attachment Notification Email. Do not display this field on the page layout.
-
Create a workflow rule with criteria Send Attachment Notification Email = True, with Evaluation Criteria: created, and any time it’s edited to subsequently meet criteria
-
Have this workflow rule send an email and do a field update to uncheck the Send Attachment Notification Email field.
Create a trigger on the Attachment to check the Send Attachment Email field when an Attachment is created.All Answers
Below code helps you please make some modificatin in code accorind to you.
IF it helps you than please mark it as a solution and ENJOY APEX
Thank you for your help.
I have follow up question though, where should I add this trigger? Because I cannot find a section to add the Attachment trigger. Should I add it to the Parent Object?
So here is your design pattern:
-
Create a checkbox field on your object called Send Attachment Notification Email. Do not display this field on the page layout.
-
Create a workflow rule with criteria Send Attachment Notification Email = True, with Evaluation Criteria: created, and any time it’s edited to subsequently meet criteria
-
Have this workflow rule send an email and do a field update to uncheck the Send Attachment Notification Email field.
Create a trigger on the Attachment to check the Send Attachment Email field when an Attachment is created.To get Gigi's code working, I had to change line 7 to:
String keyPrefix = String.valueOf(a.LinkedEntityId).substring(0, 3);
This makes it a string instead of Id and the code becomes error-free.
I modified the code a bit to get it to work for Files like so:
I am not familiar on writing code, could anyone help me on writing a new one? I need to create a trigger to check a checkbox on the Case object every time an attachment is added, then I will use this to build a process in process builder to send an email to corresponding users every time the checkbox is true AND/OR there are modifications on the case.
I am stuck on trying to write the code for the trigger. I would highly appreciate your help on it! The checkbox field name is New_Attachment__c.
Thank you, thank you, thank you.