1

I have a requirement where the ‘from address’ need to be changed . According to business logic cannot use “Organization wide email address”

When ever the record is updated , From address should display Record Owner Name not the one who updated the record .

Code :

     mail.setReplyTo(record owner email);
     mail.setSenderDisplayName('record owner name');

Error : In ‘From Address’ It should display only the record owner name not the one who updated the record**([mailto :xyz@salesforce.com])**

From: record owner name [mailto :xyz@salesforce.com] Sent: Friday, February 19, 2016 11:27 AM

  • so what is the real issue here? -- you can fetch the record owner name and email via owner.name and owner.email relationships using SOQL – cropredy May 19 '16 at 4:54
0

Here is a Salesforce article on "Setting a 'from' address in SingleEmailMessage".

To do this you must first set up a dedicated email address by navigating to Setup -> Administration Setup -> Email Administration -> Organization-Wide Addresses menu.

Once you have created an org-wide address (note that Salesforce will require you to confirm the address prior to using it, so if you're going to be sending things from a junk address it would be wise to set up a catch-all mailbox so you receive the confirmation email), grab the Id from the URL and use the setOrgWideEmailAddressId(Id)method on your instance of Messaging.SingleEmailMessage. If you want to avoid hard-coding an Id, after creating your Org-Wide Address you can query them:

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);
}

Source - https://help.salesforce.com/apex/HTViewSolution?id=000232863&language=en_US

| improve this answer | |
  • I thought he said he couldn't use org wide default email? – Francis May 18 '16 at 7:41
  • Yes without using org wide default email. .. Is there any way ? – nam May 18 '16 at 8:20
  • Why there is a negative vote? I know in the question it was mentioned. But my intention is to show how you can create multiple 'Organization wide email address' and use them as per your need. – Saroj Bera May 18 '16 at 8:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.