Note: This release is in preview. Features described here don’t become generally available until the latest general availability date that Salesforce announces for this release. Before then, and where features are noted as beta, pilot, or developer preview, we can’t guarantee general availability within any particular time frame or at all. Make your purchase decisions only on the basis of generally available products and features.
SendEmailResult
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
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. |
1Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
2email.setToAddresses(new String[] { 'admin@acme.com' });
3email.setSubject('my subject');
4email.setPlainTextBody('plain text body');
5List<Messaging.SendEmailResult> results =
6 Messaging.sendEmail(new Messaging.Email[] { email });
7if (!results.get(0).isSuccess()) {
8 System.StatusCode statusCode = results.get(0).getErrors()[0].getStatusCode();
9 String errorMessage = results.get(0).getErrors()[0].getMessage();
10}