You need to sign in to do that
Don't have an account?
Apex Error Messages send to an email.
Hi All,
Salesforce will send an email to admin when apex program execution fails(line #no and error message, etc), for which type of error it will send an email.
Thanks
Venkat.
Salesforce will send an email to admin when apex program execution fails(line #no and error message, etc), for which type of error it will send an email.
Thanks
Venkat.
<apex:page controller="sendingmailWhnExceptionoccurs">
<apex:form >
<apex:pageBlock >
<apex:pageMessages ></apex:pageMessages>
<apex:pageBlockButtons >
<apex:commandButton value="Save" action="{!saving}"/>
</apex:pageBlockButtons>
<apex:pageBlockSection >
<apex:inputText value="{!account.name}"/>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
Controller will send exception to any user. Just you need to append mail address.
public class sendingmailWhnExceptionoccurs{
public Account account{get;set;}
String sMessage;
public sendingmailWhnExceptionoccurs(){
account = new Account();
}
public Pagereference saving(){
try{
insert account;
}Catch(DMLException ex){
System.debug('Hi I am in catch block');
sMessage += 'ERROR: ' + 'An exception has occurred. Please contact your System Administrator quoting the following message -- '+ ex.getTypeName() + ':'+ex.getMessage() + ':' + ex.getLineNumber() + ':' + ex.getStackTraceString();
Apexpages.Message errorMessage1 = new Apexpages.Message(ApexPages.Severity.ERROR,sMessage );
Apexpages.addMessage(errorMessage1);
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage() ;
String[] toAddresses = new String[] {'Systemadmin@testemail.com', 'yourmail@gmail.com'};
mail.setToAddresses(toAddresses) ;
mail.setSubject('Exception occered');
String body = '<html lang="ja"><body>'+
'<br><br>'+
'This email alert is to bring to your notice that exception occured '+
'<br><br>'+
'<b>'+
'Here is detail of Exception '+
'</b>'+
'<br><br>'+ sMessage+
'</body></html>';
mail.setHtmlBody(body);
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
}
return null;
}
}