The sendEmail() call returns a list of SendEmailResult objects. Each SendEmailResult object has the following properties:
| Name | Type | Description |
|---|---|---|
| success | boolean | If sending single email: Indicates whether the email was successfully
accepted for delivery by the message transfer agent (true) or not (false). Even if success = true, it does not mean the
intended recipients received the email, as it could have bounced or
been blocked by a spam blocker. Also, even if the email is successfully
accepted for delivery by the message transfer agent, there can still
be errors in the error array related to individual addresses within
the email. If sending mass email: Indicates whether the email was successfully added to the queue for processing (true) or not (false). Even if the email was added to the queue, there can still be processing errors that prevent delivery to the intended recipients. |
| SendEmailError | Error[] | If an error occurred during the sendEmail() call, a list of SendEmailError objects is returned. For single email, errors indicate that Salesforce wasn't able to deliver the email. For mass email, errors indicate that the email wasn't added to the queue for processing. |
SendEmailError can have the following attributes:
| Name | Type | Description |
|---|---|---|
| Fields | Field[] | Reserved for future use. Array of one or more field names. Identifies which fields in the object, if any, affected the error condition. |
| Message | string | Error message text. |
| StatusCode | statusCode | A code that characterizes the error. The full list of status codes is available in the WSDL file for your organization. |
| TargetObjectId | ID | The object ID of the target for which the error occurred. |
Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage(); email.setToAddresses(new String[] { 'admin@acme.com' }); email.setSubject('my subject'); email.setPlainTextBody('plain text body'); List<Messaging.SendEmailResult> results = Messaging.sendEmail(new Messaging.Email[] { email }); if (!results.get(0).isSuccess()) { System.StatusCode statusCode = results.get(0).getErrors()[0].getStatusCode(); String errorMessage = results.get(0).getErrors()[0].getMessage(); }