You need to sign in to do that
Don't have an account?

Inconsistent behaviour with Messaging.sendEmailResult and Messaging.sendEmailError
Hey,
Anybody come across this problem before? Here's some code to send out a single e-mail:
Note the deliberately bogus e-mail address. When you run this, the following text is debug'ed out:
Messaging.SendEmailResult[
getErrors=(
Messaging.SendEmailError[
getFields=null;
getMessage=Invalid to address xx.yyy.zzz;
getStatusCode=System.StatusCode.INVALID_EMAIL_ADDRESS;
getTargetObjectId=null;
]
);
isSuccess=false;
]
Note that the getErrors() "member" is a Messaging.SendEmailError[] array, as specified in the Apex Ref Guide.
Now change the loop to
Seems reasonable, based on the first code fragment - but in fact it doesn't even compile:
and it compiles, but now throws a run-time error, to the effect that you can't cast a Messaging.SendEmailError object to a
Database.error. Seems like some sort of internal inconsistency.
OK - now here's the real WTF about this: Everything I've written here was demonstrably true until 30 min ago - but as of now -
the last loop does not throw that run-time error any more! I would just discard this msg, but it took me a certain amount of effort
and now I'd like to share my worry about the behaviour of production orgs (yes, I was testing both in Sandbox and in Prod
throughout) changing in the middle of a working day.
Thoughts/insight anyone?
Anybody come across this problem before? Here's some code to send out a single e-mail:
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage (); mail.setToAddresses ( new String[] { 'xxx.yyy.zzz' } ); mail.setSubject ( 'TEST' ); mail.setPlainTextBody ( 'TEST' ); Messaging.sendEmailResult[] results = Messaging.sendEmail ( new Messaging.SingleEmailMessage[] { mail } , False ); for ( Messaging.sendEmailResult result : results ) { if ( !result.isSuccess () ) { System.debug ( result );
} }
Note the deliberately bogus e-mail address. When you run this, the following text is debug'ed out:
Messaging.SendEmailResult[
getErrors=(
Messaging.SendEmailError[
getFields=null;
getMessage=Invalid to address xx.yyy.zzz;
getStatusCode=System.StatusCode.INVALID_EMAIL_ADDRESS;
getTargetObjectId=null;
]
);
isSuccess=false;
]
Now change the loop to
for ( Messaging.sendEmailResult result : results ) {
if ( !result.isSuccess () ) {
Messaging.sendEmailError[] errs = result.getErrors ();
}
}
Seems reasonable, based on the first code fragment - but in fact it doesn't even compile:
Illegal assignment from LIST:Database.Error to LIST:Messaging.SendEmailError
So - change the loop as follows:
Code:
for ( Messaging.sendEmailResult result : results ) {
if ( !result.isSuccess () ) {
Database.error[] errs = result.getErrors ();
}
}
and it compiles, but now throws a run-time error, to the effect that you can't cast a Messaging.SendEmailError object to a
Database.error. Seems like some sort of internal inconsistency.
OK - now here's the real WTF about this: Everything I've written here was demonstrably true until 30 min ago - but as of now -
the last loop does not throw that run-time error any more! I would just discard this msg, but it took me a certain amount of effort
and now I'd like to share my worry about the behaviour of production orgs (yes, I was testing both in Sandbox and in Prod
throughout) changing in the middle of a working day.
Thoughts/insight anyone?
did you ever get an answer on this? i have been experiencing the exact same thing today and get the conversion error at runtime as well as the compiler error at compile time depending on whether i use Database.Error or Messaging.SendEmailError respectively...
Message Edited by gregs on 12-04-2008 03:47 PM