Sunday 8 November 2015

Default from address while sending emails | Controlling 'From Address' in salesforce | Salesforce Org Wide Email Address

If you want to control the From Email address in salesforce then you can control this with "Organization-Wide Email Addresses".
An organization-wide email address associates a single email address to a user profile. Each user in the profile can send email using this address. Users will share the same display name and email address

Step 1:-  Setup "Organization-Wide Email Addresses"

1. Navigate Setup -> Email Administration ->  Organization-Wide Email Addresses

2. Click on Add button.

3. Enter email Id and display name of sender.
4. In order to complete this process you need to get verified email id you are putting here

Step 2:- Fetch "Org Wide Email Address" in code like below code.

public class EmailHelper 
 public static void sendEmail() 
  Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();  
  string body = 'Demo Body ';
  String[] toAddresses = new String[] {''}; 
  mail.setSubject('Test Subject');  
  for(OrgWideEmailAddress owa : [select id, Address, DisplayName from OrgWideEmailAddress]) 
   if(owa.DisplayName.contains('System Admin'))
  Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });

Some Use Full Link :-

Please let us know if this will help you

Amit Chaudhary

No comments:

Post a Comment