2

I am sending out an email using SingleEmailMessage. I have an Organization wide email address what I need to use as the From address. However, I am using an email template to generate the body of the email. The method setOrgWideEmailAddressId does not work when the email template is being used. Is there any way around this?

Basically I need to do this:

if ( owea.size() > 0 ) {
     email.setOrgWideEmailAddressId(owea.get(0).Id);
}
    
mail = Messaging.renderStoredEmailTemplate(emailTemplate.Id+'', accountIdContactMap.get(opp.AccountId).Id+'', opp.Id+'');
           

The only thing I can think of is to generate the email in apex with string building.

1
  • Yep. Generate and send the email, while making sure you have a reference to the email. Then rollback. The email will have content in the body (a compiled template) which you can extract and put in another email. Which you then send. Costs you an extra DML. Commented Mar 10, 2021 at 17:05

1 Answer 1

0

The solution is to set the org wide address after you render the template, as you're reassigning the message variable when you render.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .