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!
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!
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}); } }
Where is this code used? In a trigger? Controller? Batch job?

Is a method, class Schedulable
