Created
November 15, 2016 05:42
-
-
Save TonyRenHK/f271709080b7d10f65ab9688b0abaf90 to your computer and use it in GitHub Desktop.
How to send email in TriggerClass in Salesforce
This file contains 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
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage(); | |
string body = 'Hi '; | |
String[] toAddresses = new String[] {'sksworld10@gmail.com'}; | |
mail.setToAddresses(toAddresses); | |
mail.setSubject('Test Subject'); | |
mail.setSaveAsActivity(false); | |
for(OrgWideEmailAddress owa : [select id, Address, DisplayName from OrgWideEmailAddress]) | |
{ | |
if(owa.Address.contains('testuser')) | |
mail.setOrgWideEmailAddressId(owa.id); | |
} | |
mail.setHtmlBody(body); | |
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment