How do I send an email with Apex trigger?

How do I send an email with Apex trigger?

Apex Trigger: Send Email when Service Report is Created

  1. trigger sendEmail on ServiceReport (after insert) {
  2. List mails = new List
  3. List sendTo = new List();
  4. sendTo. add(‘[email protected]’);
  5. for(ServiceReport sr : trigger. new){
  6. Messaging.
  7. mail.
  8. mail.

How do I get an apex error email?

From Setup, enter Automation in the Quick Find box, then select Process Automation Settings. For Send Process or Flow Error Email to, select who gets the error emails. Apex Exception Email Recipients—Sends emails to the addresses set on the Apex Exception Email page in Setup.

How do I email an apex class?

The setSubject() function sets the subject of the mail and the setHtmlBody() sets the body of the mail in HTML form. If you want to set body in text form then use the function setPlainTextBody() function. To send the mail simply use the sendEmail() function of the Messaging class.

What is Apex exception email?

APEX exception mails, which are sent when an unhandled exception occurs in a trigger or class. Configure email addresses that receive emails when your Apex code encounters unhandled exceptions. Previously, these emails were sent only to the developer who’d last modified a failing class or trigger.

How do I send an email from Apex template in Salesforce?

Create a new template:

  1. Go to Setup-> search ‘template’ -> choose ‘Classic Email Templates’-> click on ‘New Template’ button.
  2. Select Visualforce option for ‘type of email template’.
  3. Enter template name, keep the other defaults.
  4. Enter Email Subject text.

How can you setup Governor limit email warnings in Apex?

Set Up Governor Limit Email Warnings

  1. Log in to Salesforce as an administrator user.
  2. From Setup, enter Users in the Quick Find box, then select Users.
  3. Click Edit next to the name of the user to receive the email notifications.
  4. Select the Send Apex Warning Emails option.
  5. Click Save.

Who are apex exception email recipients?

Apex Exception Email Recipients—Sends emails to the addresses set on the Apex Exception Email page in Setup. Choose this option to control who receives process or flow error emails in your org.