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[] {'abc@gmail.com'}; 
  mail.setToAddresses(toAddresses);
  mail.setSubject('Test Subject');  
  mail.setSaveAsActivity(false);  
  for(OrgWideEmailAddress owa : [select id, Address, DisplayName from OrgWideEmailAddress]) 
  {
   if(owa.DisplayName.contains('System Admin'))
   { 
    mail.setOrgWideEmailAddressId(owa.id); 
   } 
  }
  mail.setHtmlBody(body);  
  Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
    }  
}





Some Use Full Link :-
http://salesforce.stackexchange.com/questions/5169/whats-the-advantage-of-using-massemailmessage-instead-of-multiple-singleemailme/5174#5174
http://developer.force.com/cookbook/recipe/creating-email-templates-and-automatically-sending-emails

Please let us know if this will help you

Thanks
Amit Chaudhary

No comments:

Post a Comment