In my Visual Force Page,On Click of button I am sending an Email to the respective contact through apex(Using Messaging.SendEmail Method).So If the email address is not proper then I am getting this error I understood that thing.

Can we handle the error through apex and show in visual force page with some proper error message.Is it possible to show?


Yes, Messaging.sendEmail has an optional second parameter for allOrNone, which allows partial failures. In this mode, you can read the SendEmailResult responses to render errors.

That basically looks like this:

SendEmailResult[] results = Messaging.sendEmail(messages, false);
for(SendEmailResult result: results) {
    if(!result.isSuccess()) {
        // render the error somehow
  • 1
    presumably try { ..} catch (EmailException e) {// display error} works too although your solution is better as it handles lists of messages – cropredy Nov 6 '16 at 0:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.