Print this page

Override from address using SingleEmailMessage

Knowledge Article Number 000193208
Description How to setup/override in salesforce From address using SingleEmailMessage? 
Resolution

You can use the setOrgWideEmailAddressId(ID) instance method of SingleEmailMessage. To do this, first you have to setup your org wide default email address by going to Setup -> Administration Setup -> Email Administration -> Organization-Wide Addresses menu.. You can then get the ID of that email from the URL and use that in the instance method. 

OrgWideEmailAddress[] owea = [select Id from OrgWideEmailAddress where Address = 'doNotReply@blahblah.com'];
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
if ( owea.size() > 0 ) {
    mail.setOrgWideEmailAddressId(owea.get(0).Id);
}
Reference:  https://developer.salesforce.com/docs/atlas.en-us.200.0.apexcode.meta/apexcode/apex_classes_email_outbound_single.htm#apex_Messaging_SingleEmailMessage_setOrgWideEmailAddressId




promote demote