+ Start a Discussion
Eric PohlabelEric Pohlabel 

Set email alert to record owner

I have an email alert that currently sends from the current users address.  I know that I can change this to an Org-Wide default - but is there a way to dynamically change it to the record owner?

We are sending email alerts from Cases via a process flow.  The user who is kicking off the flow is not necessarily the case owner BUT I want the email that is sent to be sent from the case owner such that the case owner's email address shows in the "From" line and replies to the email go that address.
Alain CabonAlain Cabon
Sending email alerts from Cases via a process flow.

1) invocable method ( some Apex code passing the email of the case owner to the method )

A complete sample:

but it lacks the setSenderDisplayName(displayName) in the example above with an important constraint (setOrgWideEmailAddressId).

2) setSenderDisplayName(displayName) Optional. The name that appears on the From line of the email. This cannot be set if the object associated with a setOrgWideEmailAddressId for a SingleEmailMessage has defined its DisplayName field.


User-added image

public class sendAnEmail
    @InvocableMethod(label='Send an email from apex class' description='sends an email')
    public static void sendEmailWithAttachment(List<String> caseowneremails)
         for (String caseowneremail:caseowneremails) {
               Messaging.SingleEmailMessage semail= new Messaging.SingleEmailMessage();
               semail.setSubject('Quote Issued');
               String[] emailIds= new String[]{'**********@gmail.com'};
               semail.setPlainTextBody('Please find an important message');
               Messaging.sendEmail(new Messaging.SingleEmailMessage[]{semail});