You need to sign in to do that
Don't have an account?
Apex Class to send Email Notification when Account Owner is Changed
Hi All,
I want to send an email notification when account owner is changed. And also i want to send email notification to both old account owner and new account owner which has been changed. How to achieve this. Can anyone send me the code?
I want to send an email notification when account owner is changed. And also i want to send email notification to both old account owner and new account owner which has been changed. How to achieve this. Can anyone send me the code?
Use trigger...best one is workflow
All Answers
You may accomplish this using a workflow rule. This workflow would have an appropriate condition for its evaluation criteria and will have three immediate actions as follows:
- Field Update: For this, first add a new email field, and populate it here with old owner's email address (Use PRIORVALUE (https://help.salesforce.com/apex/HTViewHelpDoc?id=customize_functions_i_z.htm&language=en_US#PRIORVALUE) function).
- Email Alert: Send email to old owner, with "Recipient Type" equal to "Email Field" and then select above field.
- Email Alert: Send email to new owner.
Thanks,Suraj
Use trigger...best one is workflow
Hi Suraj,
Can you please elaborate the workflow process to achieve this.
Best, Nisha.
I haven't worked on Force.com anymore since the last 4-5 years, and so my solution may not be the best possible way to do this.
In order to send an email using workflow, we need either a field of type Email on the record that triggered the flowflow, or a field of type User (Lookup to User) on the record that triggered the flowflow.
Here we want to send two emails, one to the old owner (Let's call this email A) , and another one to the new owner (Let's call this email B).
For email A, somehow we need to store the old owner's id onto the same record, so that we could use it in a workflow email action. In order to do that, we need an additional field of type Lookup (User), and a workflow action of type Field Update. The Field Update action can make use of the PRIORVALUE function to get the old owner id and set it in the new field that we would add. This Field Update action must get executed before actual email A workflow action that would send the email to the old owner.
For email B, it is rather simple as we already have a new owner into the Owner field, and so one workflow email action would do the job.
In summary, what we need is:
1. One custom lookup field to store old owner
2. One worflow rule with three actions as below
3. First workflow action - Field Update - sets field added in #1 with the old owner id
4. Second workflow action - Email - sends email to #1 field user
5. Third workflow action - Email - sends email to Owner field user
Please let me know if you need more information.
Thanks,
Suraj Gharat