Following is a reference of methods that you can use in your Apex Logging to capture the right data in your Apex monitors, as of Job Center version 2.11
Instance Methods
- void log(String logString)
- void log(String logString, String logCategory)
- void logResult(String resultString)
- void logResult(String resultString, String resultCategory)
- void logAll(String logString)
- void logAll(String logString, String logCategory)
- void log(List<String> logList)
- void log(List<String> logList, String category)
- void logResult(List<String> logList)
- void logAll(List<String> logList)
- void logSpace()
- void logResultSpace()
- void logException (Exception e)
- void setSummaryLog(String summaryLog)
- void setSummaryResult(String summaryResult)
- void setPrimaryRecordId(Id primaryRecordId)
- void setJobRunId(String jobRunId)
- void logPopulatedFields(SObject objRecord)
- void logPopulatedFields(List<SObject> objRecordList)
- void logPopulatedFields(SObject objRecord, List<String> fieldNames)
- void logPopulatedFields(List<SObject> objRecordList, List<String> fieldNames)
- void setReviewFlag()
- void clearReviewFlag()
- void reportToJobCenter()
- void reportFailureToJobCenter()
- void reportFailureToJobCenter(Exception e)
Static Methods
- void log(String logString)
- void log(String logString, String logCategory)
- void log(List<String>, logList)
- void log(List<String>, logList, String logCategory)
- void logResult(String resultString)
- void logResult(String resultString, String resultCategory)
- void setReviewFlag()
- void clearReviewFlag()
- void logException(Exception e)
- JCLogger getJCLogger(String monitorName)
- JCLogger getJCLogger(String monitorName, Id primaryRecordId)
- void reportToJobCenter(String monitorName, List<String> logStatements)
- void reportFailureToJobCenter(String monitorName, List<String> logStatements)
- void reportFailureToJobCenter(String monitorName, List<String logStatements, Exception e)
Instance Method Name |
void log(String logString) Add a simple log statement jcLogger.log('This is my statement');
Result: 2021-08-02 18:25:30 | This is my statement |
void log(String logString, String logCategory) Add a simple log statement and category to the current log jcLogger.log('This is my statement','Error');
Result: 2021-08-02 18:25:30 | [Error] This is my statement
|
void logResult(String resultString)
Add a simple log statement to the Job Results (different than Job logs) jcLogger.logResult('This is my statement');
Result: This is my statement |
void logResult(String resultString, String resultCategory)
Add a simple log statement and category to the Job Results (different than Job logs) jcLogger.logResult('This is my statement','Error');
Result: [Error] This is my statement |
void logAll(String logString)
Add a simple log statement to both Job Logs and Job Results jcLogger.logAll('This is my statement');
Result: 2021-08-02 18:25:30 | This is my statement This is my statement |
void logAll(String logString, String logCategory)
Add a simple log statement and category to both Job Logs and Job Results jcLogger.logAll('This is my statement','Error');
Result: 2021-08-02 18:25:30 | [Error] This is my statement [Error] This is my statement |
void log(List<String> logList)
Add a collection of string values to the existing log as separate log statements jcLogger.log(new List<String>{'This is my statement', 'This is my other statement'});
Result: 2021-08-02 18:25:30 | This is my statement 2021-08-02 18:25:30 | This is my other statement |
void log(List<String> logList, String category)
Add a collection of string values and a category to the existing log as separate log statements jcLogger.log(new List<String>{'This is my statement', 'This is my other statement'},'Error');
Result: 2021-08-02 18:25:30 | [Error] This is my statement 2021-08-02 18:25:30 | [Error] This is my other statement |
void logResult(List<String> logList)
Add a collection of string values to the existing Job Results as separate log statements jcLogger.logResult(new List<String>{'This is my statement', 'This is my other statement'});
Result: This is my statement This is my other statement |
void logAll(List<String> logList)
Add a collection of string values to the existing Job Log and Job Results as separate log statements jcLogger.logAll(new List<String>{'This is my statement', 'This is my other statement'});
Result: 2021-08-02 18:25:30 | This is my statement 2021-08-02 18:25:30 | This is my other statement This is my statement This is my other statement |
void logSpace()
Add a break between groups of log statements. Helpful for readability in longer logs with lots of content. jcLogger.log('This is my statement','Error');
Result: 2021-08-02 18:25:30 | This is my statement 2021-08-02 18:25:30 | This is my other statement |
void logResultSpace()
Add a break between groups of Job Results. Helpful for readability in longer results with lots of content. jcLogger.log('This is my statement','Error');
Result: This is my statement This is my other statement |
void logException (Exception e)
Formats logging of exception content to include Exception Type, Line Number, and Message jcLogger.logException(e);
Result: 20:24:25 | [JC Logger] Type: System.MathException | Line: 18 | Message: Divide by 0 |
void setSummaryLog(String summaryLog)
Sets a Job Run's Job Run Log Summary value. A simple statement about the results of a job. jcLogger.setSummaryLog('The process completed successfully');
Result: (Job Run field value updated) |
void setSummaryResult(String summaryResult)
Sets a Job Run's Job Run Result Summary value. A simple statement about the results of a job. jcLogger.setSummaryResult('The process encountered an error');
Result: (Job Run field value updated) |
void setPrimaryRecordId(Id primaryRecordId)
Sets a Job Run's Primary Record Id value. Associates this log with a specific data record. jcLogger.setPrimaryRecordId(myObect.Id);
Result: (Job Run field value updated) |
void setJobRunId(String jobRunId)
Sets the Job Run's Job Run Id value. Job Run Id refers to a user defined string that uniquely identifies this process. Any future logs of the same type and Job Id will append their logs to the existing Job Run. jcLogger.setJobRunId('myuniquecontextid1234567890');
Result: (Logs are appened to the existing Job Run with this id) |
void logPopulatedFields(SObject objRecord)
Adds all populated field values for the supplied instance object, to the logs for this Job Run Contact myContact = new Contact(FirstName='Lionel',LastName='Messi',email='lm@bestever.com');
Result: 2021-08-02 18:25:30 |FirstName - Lionel 2021-08-02 18:25:30 |LastName - Messi 2021-08-02 18:25:30 |LastName - lm@bestever.com |
void logPopulatedFields(List<SObject> objRecordList)
Adds all populated field values for the supplied instance objects, to the logs for this Job Run Contact myContact = new Contact(FirstName='Lionel',LastName='Messi',email='lm@bestever.com');
Result: 2021-08-02 18:25:30 |FirstName - Lionel 2021-08-02 18:25:30 |LastName - Messi 2021-08-02 18:25:30 |Email - lm@bestever.com 2021-08-02 18:25:30 |FirstName - Christiano 2021-08-02 18:25:30 |LastName - Ronaldo 2021-08-02 18:25:30 |Email - cr@bestever.com |
void logPopulatedFields(SObject objRecord, List<String> fieldNames)
Adds all populated specified field values for the supplied instance object, to the logs for this Job Run Contact myContact = new Contact(FirstName='Lionel',LastName='Messi',email='lm@bestever.com');
Result: 2021-08-02 18:25:30 |LastName - Messi 2021-08-02 18:25:30 |Email - lm@bestever.com |
void logPopulatedFields(List<SObject> objRecordList, List<String> fieldNames)
Adds all populated field values for the supplied instance objects, to the logs for this Job Run Contact myContact = new Contact(FirstName='Lionel',LastName='Messi',email='lm@bestever.com');
Result: 2021-08-02 18:25:30 |Email - lm@bestever.com 2021-08-02 18:25:30 |Email - cr@bestever.com |
void setReviewFlag()
Sets the Needs Review flag for Job Runs to true. Allows for notifications when there has NOT been an exception. jcLogger.setReviewFlag();
Result: (Job Run field value updated, Result icon changed in interface) |
void clearReviewFlag()
Sets the Needs review flag for Job Runs to false. Clears the flag, if it was set earlier in the process. jcLogger.clearReviewFlag();
Result: (Job Run field value updated, Result icon changed in interface) |
void reportToJobcenter()
Commits all logs to Job Center and saves the new Job Run. Usually called at the end of a process. jcLogger.log('This is my statement');
Result: (Job Run record saved with all log statements) |
void reportFailureToJobCenter()
Commits all logs to Job Center and saves the new Job Run with a status of 'Failed'. This version of the method is used to report a job as failed for logical or strategic reasons (when there has not been an exception). Warning: Mistaking this method for the version that takes an Exception parameter is a common mistake! if(getMyCriticalRecords().size() == 0){ Result: (Job Run Committed in a Failed status. Result icon changed in interface) |
void reportFailureToJobCenter(Exception e)
Commits all logs to Job Center and saves the new Job Run with a status of 'Failed'. Usually called at the end of a process and usually utilized within appropriate exception handling try{ Result: (Job Run Committed in a Failed status. Exception data added to log. Result icon changed in interface) |
Static methods are used for two primary reasons:
- To establish a new monitor/logger within your Apex code
- To add log statements to the "current" log. For example, if you establish and complete a monitor in your controller method, and you want to add a log statements regarding functionality or logic that exists within a helper method that is called by the controller, use the static version of the log method. This allows a helper method's logs to be added to the monitor of the calling method.
Static Method Name |
static void log(String logString) Add a simple log statement to the current log JCLogger.log('This is my statement');
Result: 2021-08-02 18:25:30 | This is my statement |
static void log(String logString, String logCategory) Add a simple log statement and category to the current log JCLogger.log('This is my statement','Error');
Result: 2021-08-02 18:25:30 | [Error] This is my statement |
static void logResult(String resultString)
Add a simple log statement to the Job Results (different than Job logs) JCLogger.logResult('This is my statement');
Result: This is my statement |
void logResult(String resultString, String resultCategory)
Add a simple log statement and category to the Job Results (different than Job logs) JCLogger.logResult('This is my statement','Error');
Result: [Error] This is my statement |
void log(List<String> logList)
Add a collection of string values to the existing log as separate log statements JCLogger.log(new List<String>{'This is my statement', 'This is my other statement'});
Result: 2021-08-02 18:25:30 | This is my statement 2021-08-02 18:25:30 | This is my other statement |
void log(List<String> logList, String category)
Add a collection of string values and a category to the existing log as separate log statements JCLogger.log(new List<String>{'This is my statement', 'This is my other statement'},'Error');
Result: 2021-08-02 18:25:30 | [Error] This is my statement 2021-08-02 18:25:30 | [Error] This is my other statement |
void setReviewFlag()
Sets the Needs Review flag for a Job Run to true. Allows for notifications when there has NOT been an exception. Warning: Only relevant IF a logger has already been created JCLogger.setReviewFlag();
Result: (Job Run field value updated, Result icon changed in interface) |
void clearReviewFlag()
Sets the Needs review flag for Job Runs to false. Clears the flag, if it was set earlier in the process. Warning: Only relevant IF a logger has already been created JCLogger.clearReviewFlag();
Result: (Job Run field value updated, Result icon changed in interface) |
void logException (Exception e)
Formats logging of exception content to include Exception Type, Line Number, and Message Warning: Only relevant IF a logger has already been created JCLogger.logException(e);
Result: 20:24:25 | [JC Logger] Type: System.MathException | Line: 18 | Message: Divide by 0 |
JCLogger getJCLogger(String monitorName)
Creates a new monitor (Job Run) instance to which logs can be added JCLogger jcl = JCLogger.getJCLogger('My New Monitor');
Result: (A new JC Job Run record is created. A new JC Job record is created, if necessary) |
JCLogger getJCLogger(String monitorName, Id primaryRecordId)
Creates a new monitor (Job Run) instance to which logs can be added. Associates the Job Run with a particular data record for easier debugging. Note: This is not appropriate for All monitors (for example a batch job), but should be used as often as possible to support faster debugging and clear association between logs and data issues. Contact contact = getMyContact();
Result: (A new JC Job Run record is created. Job Run's Primary Record Id value is set. A new JC Job record is created, if necessary. ) |
void reportToJobCenter(String monitorName, List<String> logStatements) Creates a new monitor (Job Run) instance and reports it to Job Center in a "One-Liner" Note: The String list may be defined inline, at the developer's discretion List<String> logList = new List<String>();
Result: 2021-08-02 18:25:30 | This is my statement 2021-08-02 18:25:30 | This is my other statement |
void reportFailureToJobCenter(String monitorName, List<String> logStatements) Note: The String list may be defined inline, at the developer's discretion List<String> logList = new List<String>();
Result: (Job Run is created with a 'Failed' status) 2021-08-02 18:25:30 | This is my statement 2021-08-02 18:25:30 | This is my other statement |
void reportFailureToJobCenter(String monitorName, List<String logStatements, Exception e) Note: The String list may be defined inline, at the developer's discretion List<String> logList = new List<String>();
Result: (Job Run is created with a 'Failed' status) 2021-08-02 18:25:30 | This is my statement 2021-08-02 18:25:30 | This is my other statement [JC Logger] Type: System.MathException | Line: 18 | Message: Divide by 0 |
Comments
Please sign in to leave a comment.