Created
June 17, 2020 13:37
-
-
Save techb/7519e95bac3caa2b8adb3f65d2dc2dc8 to your computer and use it in GitHub Desktop.
Utility for sending single emails in Apex with an org-wide email address
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class EmailSend { | |
public static void sendEmail(String candidate){ | |
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage(); | |
mail.setToAddresses(new String[]{candidate}); | |
mail.setReplyTo('hr_address@my_company.com'); | |
mail.setSubject('Thank You'); | |
// https://help.salesforce.com/articleView?id=000340122&type=1&mode=1 | |
// org-wide email address needs to be set | |
OrgWideEmailAddress[] owea = [select Id from OrgWideEmailAddress where Address = 'hr_address@my_company.com']; | |
if ( owea.size() > 0 ) { | |
mail.setOrgWideEmailAddressId(owea.get(0).Id); | |
} | |
mail.setHtmlBody('<p>Your message has been recieved</p>'); | |
mail.setPlainTextBody('Your message has been recieved'); | |
Messaging.sendEmail(new Messaging.SingleEmailMessage[]{mail}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment