Sending email in Salesforce

How to send email in TriggerClass in Salesforce?

Solution

The following code is added class to call email template to send email to
certain email address.The code like this:

Generally we send emails from Salesforce using following ways :

  1. Apex Code

  2. Email Alerts

  3. Outbound messaging etc.

In all of these ways we normally set ‘To’/‘Cc’/‘Bcc’ but have you thought how to control ‘From address of email’? what to do if we need to send email displaying any other email address in ‘from’ part instead of sender’s email address. Here is one Salesforce feature to get rid of this problem that is “Organization-Wide Email Addresses”.

alt tag

In above screen shot you just need to

  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 ( in this example it is 'testuser@gmail.com‘).

Now it is ready for use. Let’s see how we can use it in Apex code side:-

example :

Here you can notice that we can control ‘From address’ in sending email.