Skip to content

Instantly share code, notes, and snippets.

@srujan21
Created February 3, 2020 11:19
Show Gist options
  • Save srujan21/f2a58ed1e7868abb97cfc5d8b2f41aec to your computer and use it in GitHub Desktop.
Save srujan21/f2a58ed1e7868abb97cfc5d8b2f41aec to your computer and use it in GitHub Desktop.
Code to capture Exceptions and errors
/**************************************************
* Class: ExceptionLogUtilityClass
* Author: Soljit - SR
* Date: 2019-06-18
*
* Description: Utility class which can be called to insert Exception logs
*
* V1.0: Initial
*
****************************************************/
global class ExceptionLogUtilityClass {
/***************************************************
* Creates and returns Exception log object with data extracted from incoming exception
*
* ***************************************************/
global static soljit_sl5__Exception_Log__c createExceptionLog(Exception vEx){
soljit_sl5__Exception_Log__c eL = new soljit_sl5__Exception_Log__c ();
eL.Exception_Type__c = vEx.getTypeName();
eL.Integration_Response__c= False;
eL.Line_Number__c = vEx.getLineNumber();
eL.Exception_Details__c = vEx.getStackTraceString();
eL.Exception_Message__c = vEx.getMessage();
eL.Component__c = vEx.getStackTraceString().split(':')[0];
return eL;
}
/***************************************************
* Inserts exception as eLog
*
* ***************************************************/
global static void insertELog(Exception e){
INSERT createExceptionLog(e);
}
global static void insertAPIResponse(String vResponse, Integer statusCode, string component){
INSERT CaptureAPIResponse(vResponse, statusCode, component);
}
/***************************************************
* Captures the API response
*
* ***************************************************/
global static soljit_sl5__Exception_Log__c CaptureAPIResponse(String vResponse, Integer statusCode, string component){
soljit_sl5__Exception_Log__c eL = new soljit_sl5__Exception_Log__c ();
eL.Integration_Response__c= True;
eL.Exception_Message__c = vResponse;
eL.Line_Number__c = statusCode;
eL.component__c = component;
return eL;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment