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

Query Verify
hello
I would like to send an email containing the error message if the wrong type a User request (example: select name from cont or selecttttttttttttttttttttttt).
I tried the above code but not get the email when the request is wrong.
Help me!
if I submit one request that returns empty value, it sends email
if I submit one request that returns values, it sends email
if I report a wrong request, it does not send email ... WHY????????????
I would like to send an email containing the error message if the wrong type a User request (example: select name from cont or selecttttttttttttttttttttttt).
I tried the above code but not get the email when the request is wrong.
Help me!
if I submit one request that returns empty value, it sends email
if I submit one request that returns values, it sends email
if I report a wrong request, it does not send email ... WHY????????????
string queryResultatString = ''; list<sObject> queryResultat; System.QueryException q; try { queryResultat = (List<sObject>)database.query(requete); if (queryResultat.isEmpty()){ String errMsg = 'EMPTY'; Messaging.SingleEmailMessage email =new Messaging.SingleEmailMessage(); String[] adressMail = new list<string> {mail}; String subject = Label.StreamReport+' - '+Date.today().format(); email.setSubject(subject); email.setToAddresses(adressMail); email.setPlainTextBody(Label.Hi+'\n\n'+errMsg ); Messaging.SendEmailResult [] envoyer = Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email}); } else if (!queryResultat.isEmpty()){ for(sObject a: queryResultat) { queryResultatString = queryResultatString + string.valueof(a); } } } catch (System.QueryException e){ if (e.getMessage() != null){ String error = e.getMessage(); Messaging.SingleEmailMessage email =new Messaging.SingleEmailMessage(); String[] adressMail = new list<string> {mail}; String subject = Label.StreamReport+' - '+Date.today().format(); email.setSubject(subject); email.setToAddresses(adressMail); email.setPlainTextBody(Label.Hi+'\n\n'+error ); Messaging.SendEmailResult [] envoyer = Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email}); } }
The only thing I can suggest now is to check your emails(sender and reciever), maybe there is some mistake. But basing your description it shouldn't send emails in the other cases.
All Answers
Could you provide example of the "Wrong" request ?
or
selecttttttttttttttttttttttt
or
fsdfsdfsdfdsfsdfsdfsdfsdf
Try to request "Email Logs" and look there.
how i do it?
2) Press Request an Email Log
3) Set start/end date of neede interval. and set email to which you sent emails in your code.
It can take some time before you recieve log files. They are in CSV format(as I remember), There you can look at delivery status and error type if it available.
Date Time, Internal Message ID, Mail Event, Recipient, Sender, Remote Host, Bytes Transferred, Salesforce.com User, Message ID Header, Retry Count, Seconds In Queue, Delivery Stage, Relay Address, ,
"07/24/2014 07:20:17","84/19-29354-1B3B0D35",R,"v.vvvvvv@vvvvvvvv.com","vvv******=gmail.com__q4ruhdb3qrcmut2o@l4tl7za50e4.2-mybjeam.eu0.bnc.salesforce.com","10.237.71.4",3559,00520000003HHTG,"<-4Jvo000000000000000000000000000000000000000000000N97GDD00-GCi-aVnTFWOoiCN2p4HoA@sfdc.net>",,,,,,
Why did I not receive emails?
The line: System.debug('ALGO ACONTECEU AQUI: ' + e.getMessage()); works!
What am I doing wrong?
The only thing I can suggest now is to check your emails(sender and reciever), maybe there is some mistake. But basing your description it shouldn't send emails in the other cases.