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
RRRizeRRRize 

Send email as someone else specified in a lookup field - Apex Trigger

In Opportunities, I have a required custom user lookup field called Sales Representative.  I currently have a bunch of cumbersome workflow rules set up to send email as the Sales Representative specified in that lookup field. (I created org-wide email addresses for the Sales Reps).  The sales assistant almost always creates the opportunities for the sales reps.  What makes the workflows so cumbersome is that each sales assistant has multiple sales people assigned to them so I have to ake multiple workflow rules for each sales assistant.

 

I would like to create a trigger that will simply send out an email as the sales rep who is specified in the Sales Representative lookup field.  Is this possible?  If so, please expound on how to go about it.  I've been working on it with a developer here, but we have not been able to figure out how to send email AS someone else if that someone else will be different every time.

 

Please help!  Thanks!

Best Answer chosen by Admin (Salesforce Developers) 
JD2010JD2010

If I understand you correctly, then what you want to do is, when creating the trigger, set the replyTo address as the user's email whom you want to be the sender, and the SenderDisplayName to be that of the sales rep.

 

IE:

 

email.setReplyTo(opp.Owner.Email);

email.setSenderDisplayName(opp.Owner.Name);

All Answers

JD2010JD2010

If I understand you correctly, then what you want to do is, when creating the trigger, set the replyTo address as the user's email whom you want to be the sender, and the SenderDisplayName to be that of the sales rep.

 

IE:

 

email.setReplyTo(opp.Owner.Email);

email.setSenderDisplayName(opp.Owner.Name);

This was selected as the best answer
RRRizeRRRize

Your response gave me a Duhhh moment!  Your IE is exactly what I need to use.  I was thinking far too complicated!  Thanks so much!