function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
TehNrdTehNrd 

Building a Custom Exception Log

One of this issues we have run across while developing code is notifying the correct people when there is an exception in the production environment. Currently, only the code creator receives the email notification but we would like to notify more than one person. What I have done is created a custom object that is populated when an exception occurs. We would then be able to use work flow to notify the correct people.
Code:
trigger triggerName on Object bulk (before insert) {
 
 try{
  //Trigger Code
 }catch(Exception e){
  Apex_Exception__c error = new Apex_Exception__c(
   Name = 'Apex Exception - ' + System.now(),
   Error_Message__c = e.getMessage(),
   Exception_Type__c = e.getTypeName()
  );
   
  insert error;
 } 
}
The shortcoming is that I don't know what trigger and what line caused the exception. Essentially I'd like to re-create the e-mail exception alerts:
Code:
Salesforce Sandbox

Apex script unhandled trigger exception by user/organization: ASDF34ARAFAWF/AF3FAW34FAW4

productEmailAlertsOnOpportunityProducts: execution of BeforeInsert caused by: System.NullPointerException: Attempt to de-reference a null object Trigger.productEmailAlertsOnOpportunityProducts: line 33, column 26
I looked over the the system methods but didn't see any that returned Trigger Name or more granular error messages. Anyone know how I can approach this?
 




TehNrdTehNrd
Silly me. The trigger name is not going to change so I can just manually code that in:

Trigger__c = 'Trigger Name';

The only thing I can't figure out how to do is replicate the line and column of where the error occurred.



Message Edited by TehNrd on 09-03-2007 09:50 PM

StianSStianS
Hi,

can we be notified by email when an exception occurs in our Apex code?

-Stian