function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Sandeep123Sandeep123 

How to set "From" when sending Email using Workflow.

Hi,

From a force.com site, I am updating a record and once record is updated using a workflow and on the record update I am sending an email.
Therefore, the email which is send is have from as the Site's user name and email address. Instead of that we want to add a different name as From there in the email.

Please note, we don't want to use Org wide email address as this is going to static for all this type of email address. Instead I'd like to assign the user who previously modified the record before the Site user modified it or may be i want to assign From as one of Lookup(User) field. 

If that is not possible with standard email alert workflow then please suggest any apex solution. 
Kiranpreet KaurKiranpreet Kaur
I dont think it is possible with workflows as from address form workflow contains only following option:-
1.Current user email address
2.Orgwide user email address
3.Default user.

In this case you can have following options:-
1. Apex trigger:
You can use apex trigger instead of workflow. Just create a apex trigger on update. In this trigger just check if that particular field value changed or not by comparing the old and new values in trigger. Then send email from trigger. I amnot sure whether we can send email from trigger or not. But if not then use future mehtod. Call future method from the apex trigger and send email from future method code.

2. Process builder with invocable method:
In this case first create invocable method and write a code to send email with that particular from address. Call this apex method from process builder.
 
Saravanan Sivalingam 1Saravanan Sivalingam 1
If you send to the previously user modified email address,
 
Step1: you need to create a formula field, which should store the email address of the previously editor. (note: formula field can’t be used in email alerts).
Step 2: after that you must create workflow.
 There using the field update, you must update that email address (that you’ve got from the formula field) into another email address field (you must create a custom field with email data type) in your record.
 
Step 3: Then you can choose the email field in your email alert, so you can the email to your prev owner.
If this solved your questions, please chose this as the best answer.

Thanks,
Sarvanan Sivalingam.
Sandeep123Sandeep123
Sarvanan, actually your soultion will work only when we need to set To addres. I am looking for to set "From" address.

Kiranpreet Kaur, is there way we can set From Address using apex, i mean when we send email (Messaging.SingleEmailMessage ) using apex class, trigger. ?
Kiranpreet KaurKiranpreet Kaur
Sandeep123,

I think this following will work.

mail.setReplyTo(fromaddress);
mail.setSenderDisplayName(fromNAme);

But I have doubt that it display only name but the email address is like noreply@blahblah.com

Actually I have same situation but I have use some another trick which a little bit length but it works for me. I have lead and their lead owners and I have to send email to leads form lead owners.

For this I have used workflow.

Steps:-
1. Create workflows for all the differnt user. Like I have 3 user as User1, User2 and User3. They are record owners. Workflows as:
workflow user 1
workflow user 2
workflow user 3

2. In every workflow criteria I used to check the name of record owner like in "workflow user 1" the criteria is:-
Lead.Owner.name='User1'
that if the record is having the User1 as its record owner then that workflow will start. Similarly for others.

3. I also put all the user in Org wide email address. Aslo activate all the user so that they are aviliable in email alerts.

4. Now Next step is to send email in these workflow. I have created different email alerts for all the workflow like
Email Alert Workflow user1
Email Alert Workflow user2
Email Alert Workflow user3

In every email alert I have harcoded the From Email Address like in  "Email Alert Workflow user1" the From Email Address is 'User1'. Similarly others.

It works for me. Let me know if any doubt.
 
Sandeep123Sandeep123
Hi Kiranpreet, this will work only if you have static and limited number of users. I am looking for dynamic From address.