-
-
Notifications
You must be signed in to change notification settings - Fork 232
Expand file tree
/
Copy pathLogger.cls
More file actions
4134 lines (3709 loc) · 209 KB
/
Logger.cls
File metadata and controls
4134 lines (3709 loc) · 209 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//------------------------------------------------------------------------------------------------//
// This file is part of the Nebula Logger project, released under the MIT License. //
// See LICENSE file or go to https://github.com/jongpie/NebulaLogger for full license details. //
//------------------------------------------------------------------------------------------------//
/**
* @group Logger Engine
* @description The core class for logging
* @see LogEntryEventBuilder
* @see LogMessage
*/
@SuppressWarnings(
'PMD.AvoidDebugStatements, PMD.AvoidGlobalModifier, PMD.CognitiveComplexity, PMD.CyclomaticComplexity, PMD.ExcessiveClassLength, PMD.ExcessivePublicCount, PMD.NcssTypeCount, PMD.PropertyNamingConventions, PMD.StdCyclomaticComplexity'
)
global with sharing class Logger {
// There's no reliable way to get the version number dynamically in Apex
@TestVisible
private static final String CURRENT_VERSION_NUMBER = 'v4.17.5';
private static final System.LoggingLevel FALLBACK_LOGGING_LEVEL = System.LoggingLevel.DEBUG;
private static final List<LogEntryEventBuilder> LOG_ENTRIES_BUFFER = new List<LogEntryEventBuilder>();
private static final String MISSING_SCENARIO_ERROR_MESSAGE = 'No logger scenario specified. A scenario is required for logging in this org.';
private static final String ORGANIZATION_DOMAIN_URL = System.URL.getOrgDomainUrl()?.toExternalForm();
private static final String REQUEST_ID = System.Request.getCurrent().getRequestId();
private static final Map<String, SaveMethod> SAVE_METHOD_NAME_TO_SAVE_METHOD = new Map<String, SaveMethod>();
private static final Map<Schema.SObjectField, Object> TRANSACTION_FIELD_TO_VALUE = new Map<Schema.SObjectField, Object>();
private static final String TRANSACTION_ID = System.UUID.randomUUID().toString();
private static AsyncContext currentAsyncContext;
private static String currentEntryScenario;
private static LoggerSettings__c currentUserSettings;
@TestVisible
private static String lastSaveMethodNameUsed;
private static List<String> orderedScenarios = new List<String>();
private static String parentLogTransactionId;
@TestVisible
private static Integer saveLogCallCount = 0;
private static Boolean suspendSaving = false;
@TestVisible
private static System.Quiddity transactionQuiddity = loadTransactionQuiddity();
private static String transactionScenario;
private static final List<String> CLASSES_TO_IGNORE {
get {
if (CLASSES_TO_IGNORE == null) {
CLASSES_TO_IGNORE = new List<String>{
'Class.' + Logger.class.getName(),
'Class.' + LogEntryEventBuilder.class.getName(),
'Class.' + LogMessage.class.getName()
};
}
return CLASSES_TO_IGNORE;
}
set;
}
private static final LogEntryEventBuilder.LoggingContext LOGGING_CONTEXT {
get {
if (LOGGING_CONTEXT == null) {
LOGGING_CONTEXT = new LogEntryEventBuilder.LoggingContext(
getVersionNumber(),
getOrganizationApiVersion(),
ORGANIZATION_DOMAIN_URL,
REQUEST_ID,
getCurrentQuiddity(),
getTransactionId()
);
}
return LOGGING_CONTEXT;
}
set;
}
private static final String ORGANIZATION_API_VERSION {
get {
if (ORGANIZATION_API_VERSION == null) {
// Small hack to determine the org's current API version (since Apex doesn't natively provide it)
// Serializing any SObject w/ an ID will include the API version
// So, use System.UserInfo.getUserId() to create the current user's record without querying
// Then parse the JSON to get the API version
// Expected JSON: {"attributes":{"type":"Schema.User","url":"/services/data/v53.0/sobjects/Schema.User/005J000000AugnYIAR"}
String userJson = System.JSON.serialize(new Schema.User(Id = System.UserInfo.getUserId()));
ORGANIZATION_API_VERSION = userJson.substringAfter('/data/').substringBefore('/sobjects/User');
}
return ORGANIZATION_API_VERSION;
}
set;
}
private static final String USER_SESSION_ID {
get {
if (USER_SESSION_ID == null) {
// TODO Spring '24 release - simplify this (and other lazy-loaded values)
// by switching to the fancy, new ?? null coalescing operator
try {
USER_SESSION_ID = System.UserInfo.getSessionId();
} catch (Exception ex) {
USER_SESSION_ID = '';
}
// If System.UserInfo.getSessionId() returns null, set to an empty string to
// avoid calling System.UserInfo.getSessionId() again
USER_SESSION_ID = USER_SESSION_ID ?? '';
}
return USER_SESSION_ID;
}
set;
}
private static String transactionSaveMethodName {
get {
if (transactionSaveMethodName == null) {
transactionSaveMethodName = getUserSettings().DefaultSaveMethod__c;
}
return transactionSaveMethodName;
}
set;
}
private static System.LoggingLevel userLoggingLevel {
get {
if (userLoggingLevel == null || userLoggingLevel.name() != getUserSettings().LoggingLevel__c) {
userLoggingLevel = getLoggingLevel(getUserSettings().LoggingLevel__c);
}
return userLoggingLevel;
}
set;
}
static {
// One of a few limited places in the codebase (except tests) that should use System.debug()
// The rest of the codebase should use a method in Logger.cls
System.debug(System.LoggingLevel.INFO, 'Nebula Logger - Version Number: ' + getVersionNumber());
System.debug(System.LoggingLevel.INFO, 'Nebula Logger - Transaction ID: ' + getTransactionId());
System.debug(System.LoggingLevel.INFO, 'Nebula Logger - Request ID: ' + REQUEST_ID);
System.debug(System.LoggingLevel.INFO, 'Nebula Logger - Organization API Version: ' + getOrganizationApiVersion());
setScenario(getUserSettings().DefaultScenario__c);
}
/**
* @description Enum used to control how LogEntryEvent__e records are inserted
*/
global enum SaveMethod {
EVENT_BUS,
QUEUEABLE,
REST,
SYNCHRONOUS_DML
}
// System info methods
/**
* @description Returns the current version number of Nebula Logger
* @return The current version number, in the format `v0.0.0`
*/
global static String getVersionNumber() {
return CURRENT_VERSION_NUMBER;
}
// TODO delete
/**
* @description **This is only intended to be used internally by Nebula Logger, and is subject to change.**
* Returns the current namespace of Nebula Logger
* @return The current namespace prefix, or an empty string when no namespace is being used
*/
public static String getNamespacePrefix() {
String className = Logger.class.getName();
return className.contains('.') ? className.substringBefore('.') : '';
}
/**
* @description **This is only intended to be used internally by Nebula Logger, and is subject to change.**
* Returns the current Salesforce API version number of the org
* @return The current API version, in the format `v00.0`
*/
public static String getOrganizationApiVersion() {
return ORGANIZATION_API_VERSION;
}
// Settings management methods
/**
* @description Returns the request ID generated by Salesforce for a particular transaction.
* This value is stored in `LogEntryEvent__e.RequestId__c` and `Log__c.RequestId__c`.
* @return String - The value returned by `System.Request.getCurrent().getRequestId()`
*/
// TODO decide if this should be made `global` in a future release
public static String getRequestId() {
return REQUEST_ID;
}
/**
* @description Returns the unique ID generated by Nebula Logger for a particular transaction.
* This value is stored in `LogEntryEvent__e.TransactionId__c` and `Log__c.TransactionId__c`.
* @return String - A `UUID` value generated by Nebula Logger, using `System.UUID.randomUUID().toString()`
*/
global static String getTransactionId() {
return TRANSACTION_ID;
}
/**
* @description Returns the System.Quiddity context of the current transaction.
* @return System.Quiddity - The value of System.Request.getCurrent().getQuiddity()
*/
global static System.Quiddity getCurrentQuiddity() {
return transactionQuiddity;
}
/**
* @description Stores additional details about the current transacation's async context
* @param batchableContext - The instance of `Database.BatchableContext` to track
*/
global static void setAsyncContext(Database.BatchableContext batchableContext) {
if (batchableContext != null) {
setAsyncContext(new AsyncContext(batchableContext));
}
}
/**
* @description Stores additional details about the current transacation's async context
* @param finalizerContext - The instance of `System.FinalizerContext` to track
*/
global static void setAsyncContext(System.FinalizerContext finalizerContext) {
if (finalizerContext != null) {
setAsyncContext(new AsyncContext(finalizerContext));
}
}
/**
* @description Stores additional details about the current transacation's async context
* @param queueableContext - The instance of `System.QueueableContext` to track
*/
global static void setAsyncContext(System.QueueableContext queueableContext) {
if (queueableContext != null) {
setAsyncContext(new AsyncContext(queueableContext));
}
}
/**
* @description Stores additional details about the current transacation's async context
* @param schedulableContext - The instance of `System.SchedulableContext` to track
*/
global static void setAsyncContext(System.SchedulableContext schedulableContext) {
if (schedulableContext != null) {
setAsyncContext(new AsyncContext(schedulableContext));
}
}
/**
* @description Relates the current transaction's log to a parent log via the field Log__c.ParentLog__c
* This is useful for relating multiple asynchronous operations together, such as batch & queueable jobs.
* @param parentTransactionId - The transaction ID of the original parent transaction
*/
global static void setParentLogTransactionId(String parentTransactionId) {
if (parentTransactionId != getTransactionId()) {
parentLogTransactionId = parentTransactionId;
}
}
/**
* @description Returns the transaction ID value that will be used to relate the current transaction's log to a parent log
* @return String - The parent log's transaction ID. This must be explicitly set by calling setParentLogTransactionId(String)
*/
global static String getParentLogTransactionId() {
return parentLogTransactionId;
}
/**
* @description Sets a field value on every generated `LogEntryEvent__e` record
* @param field The `Schema.SObjectField` token of the field to populate
* on each `LogEntryEvent__e` record in the current transaction
* @param fieldValue The `Object` value to populate in the provided field
*/
global static void setField(Schema.SObjectField field, Object fieldValue) {
setField(new Map<Schema.SObjectField, Object>{ field => fieldValue });
}
/**
* @description Sets multiple field values oon every generated `LogEntryEvent__e` record
* @param fieldToValue An instance of `Map<Schema.SObjectField, Object>` containing the
* the fields & values to populate on each `LogEntryEvent__e` record in the current transaction
*/
global static void setField(Map<Schema.SObjectField, Object> fieldToValue) {
if (getUserSettings().IsEnabled__c == false) {
return;
}
TRANSACTION_FIELD_TO_VALUE.putAll(fieldToValue);
TRANSACTION_FIELD_TO_VALUE.remove(null);
}
/**
* @description Indicates if logging has been enabled for the current user, based on the custom setting LoggerSettings__c
* @return Boolean
*/
global static Boolean isEnabled() {
return getUserSettings().IsEnabled__c;
}
/**
* @description Indicates if logging for the specified logging level is enabled for the current user, based on the custom setting LoggerSettings__c
* @param loggingLevel - The logging level to check
* @return Boolean
*/
global static Boolean isEnabled(System.LoggingLevel loggingLevel) {
return isEnabled() && meetsUserLoggingLevel(loggingLevel);
}
/**
* @description Indicates if logging level 'ERROR' is enabled for the current user, based on the custom setting LoggerSettings__c
* @return Boolean
*/
global static Boolean isErrorEnabled() {
return isEnabled(System.LoggingLevel.ERROR);
}
/**
* @description Indicates if logging level 'WARN' is enabled for the current user, based on the custom setting LoggerSettings__c
* @return Boolean
*/
global static Boolean isWarnEnabled() {
return isEnabled(System.LoggingLevel.WARN);
}
/**
* @description Indicates if logging level 'INFO' is enabled for the current user, based on the custom setting LoggerSettings__c
* @return Boolean
*/
global static Boolean isInfoEnabled() {
return isEnabled(System.LoggingLevel.INFO);
}
/**
* @description Indicates if logging level 'DEBUG' is enabled for the current user, based on the custom setting LoggerSettings__c
* @return Boolean
*/
global static Boolean isDebugEnabled() {
return isEnabled(System.LoggingLevel.DEBUG);
}
/**
* @description Indicates if logging level 'FINE' is enabled for the current user, based on the custom setting LoggerSettings__c
* @return Boolean
*/
global static Boolean isFineEnabled() {
return isEnabled(System.LoggingLevel.FINE);
}
/**
* @description Indicates if logging level 'FINER' is enabled for the current user, based on the custom setting LoggerSettings__c
* @return Boolean
*/
global static Boolean isFinerEnabled() {
return isEnabled(System.LoggingLevel.FINER);
}
/**
* @description Indicates if logging level 'FINEST' is enabled for the current user, based on the custom setting LoggerSettings__c
* @return Boolean
*/
global static Boolean isFinestEnabled() {
return isEnabled(System.LoggingLevel.FINEST);
}
/**
* @description Indicates if the specified logging level is enabled for the current user, based on the custom setting LoggerSettings__c
* @param logEntryLoggingLevel the logging level to check.
* @return Boolean
*/
global static Boolean meetsUserLoggingLevel(System.LoggingLevel logEntryLoggingLevel) {
return logEntryLoggingLevel.ordinal() >= userLoggingLevel.ordinal();
}
/**
* @description Returns the logging level for the current user, based on the custom setting LoggerSettings__c
* @return System.LoggingLevel - The matching instance of LoggingLevel
*/
global static System.LoggingLevel getUserLoggingLevel() {
return userLoggingLevel;
}
/**
* @description **This is only intended to be used internally by Nebula Logger, and is subject to change.**
* Creates a new, unsaved `LoggerSettings__c` record
* @return A new `LoggerSettings__c` record, with all fields populated with default field values
*/
public static LoggerSettings__c createSettings() {
return (LoggerSettings__c) Schema.LoggerSettings__c.SObjectType.newSObject(null, true);
}
/**
* @description **This is only intended to be used internally by Nebula Logger, and is subject to change.**
* Returns the current user's instance of `LoggerSettings__c`
* @return LoggerSettings__c - The current user's instance of the custom settings
*/
public static LoggerSettings__c getUserSettings() {
// Only load the current user's settings once - this allows the instance to be modified in memory (as well as upserted if any changes should be persisted)
if (currentUserSettings == null) {
Schema.User currentUser = new Schema.User(Id = System.UserInfo.getUserId(), ProfileId = System.UserInfo.getProfileId());
currentUserSettings = getUserSettings(currentUser);
}
return currentUserSettings;
}
/**
* @description **This is only intended to be used internally by Nebula Logger, and is subject to change.**
* Returns the specified user's instance of `LoggerSettings__c`
* @param loggingUser The user record - at a minimum, this record should have the user Id and Profile fields populated
* @return LoggerSettings__c - The specified user's instance of the custom settings
*/
public static LoggerSettings__c getUserSettings(Schema.User loggingUser) {
// Typically, using LoggerSettings__c.getInstance() would be easier
// However, some settings fields are expected to have null values, which conflicts with how `getInstance()` behaves
// So, instead use LoggerSettings__c.getValues(Id userOrProfileId) to load exactly what's been configured (including nulls)
// TODO cache the generated instances of LoggerSettings__c in LoggerCache.getTransactionCache().put()
// (key would be 'Settings' + user ID)
LoggerSettings__c loggingUserSettings;
// First, check for Schema.User-level settings
if (loggingUser.Id != null && LoggerSettings__c.getValues(loggingUser.Id) != null) {
LoggerSettings__c userSettings = LoggerSettings__c.getValues(loggingUser.Id);
if (hasValidStartAndEndTimes(userSettings)) {
loggingUserSettings = userSettings;
}
}
// Next, check for Profile-level settings
if (loggingUserSettings == null && loggingUser.ProfileId != null && LoggerSettings__c.getValues(loggingUser.ProfileId) != null) {
LoggerSettings__c profileSettings = LoggerSettings__c.getValues(loggingUser.ProfileId);
if (hasValidStartAndEndTimes(profileSettings)) {
loggingUserSettings = profileSettings;
}
}
// Next, use the org defaults (if configured)
if (loggingUserSettings == null && loggingUser.Id != null && LoggerSettings__c.getOrgDefaults().Id != null) {
LoggerSettings__c orgDefaults = LoggerSettings__c.getOrgDefaults();
if (hasValidStartAndEndTimes(orgDefaults)) {
loggingUserSettings = orgDefaults;
}
}
// Finally, as a last resort, create an instance using default field values
if (loggingUserSettings == null) {
loggingUserSettings = createSettings();
}
// If the settings were loaded from the org or profile level, clear the ID and make the user the SetupOwnerId (since the method is getUserSettings)
// This allows the ability to then upsert the instance of LoggerSettings__c and it will always be specific to that user...
// which avoids accidentally changing something at the org or profile levels
if (loggingUser.Id != null && loggingUserSettings.SetupOwnerId != loggingUser.Id) {
loggingUserSettings.Id = null;
loggingUserSettings.SetupOwnerId = loggingUser.Id;
}
return loggingUserSettings;
}
// Transaction control methods
/**
* @description Indicates if saving has been temporarily suspended for the current transaction
* @return Boolean
*/
global static Boolean isSavingSuspended() {
return suspendSaving;
}
/**
* @description Pauses saving for the current transaction.
* Any calls to saveLog() are ignored until saving is resumed.
*/
global static void suspendSaving() {
suspendSaving = true;
}
/**
* @description Resumes saving for the current transaction, used to reverse suspendSaving().
* Any calls to saveLog() are ignored until saving is resumed.
*/
global static void resumeSaving() {
suspendSaving = false;
}
/**
* @description Returns the number of entries that have been generated but not yet saved
* @return Integer
*/
global static Integer getBufferSize() {
return LOG_ENTRIES_BUFFER.size();
}
/**
* @description Discards any entries that have been generated but not yet saved
*/
global static void flushBuffer() {
LOG_ENTRIES_BUFFER.clear();
}
// Exception methods - these all use ERROR logging level & automatically save & throw the provided exception
/**
* @description Creates a new log entry with logging level == `System.LoggingLevel.ERROR`,
* automatically saves the log, and then throws the provided exception
* @param logMessage The instance of `LogMessage` to use to set the entry's message field
* @param apexException The instance of `System.Exception` to log and throw
*/
global static void exception(LogMessage logMessage, System.Exception apexException) {
error().setExceptionDetails(apexException).setMessage(logMessage);
saveLog(SaveMethod.EVENT_BUS);
throw apexException;
}
/**
* @description Creates a new log entry with logging level == `System.LoggingLevel.ERROR`,
* automatically saves the log, and then throws the provided exception
* @param logMessage The instance of `LogMessage` to use to set the entry's message field
* @param recordId The record ID of an `SObject` to log
* @param apexException The instance of `System.Exception` to log and throw
*/
global static void exception(LogMessage logMessage, Id recordId, System.Exception apexException) {
error().setRecordId(recordId).setExceptionDetails(apexException).setMessage(logMessage);
saveLog(SaveMethod.EVENT_BUS);
throw apexException;
}
/**
* @description Creates a new log entry with logging level == `System.LoggingLevel.ERROR`,
* automatically saves the log, and then throws the provided exception
* @param logMessage The instance of `LogMessage` to use to set the entry's message field
* @param record The `SObject` record to log
* @param apexException The instance of `System.Exception` to log and throw
*/
global static void exception(LogMessage logMessage, SObject record, System.Exception apexException) {
error().setRecordId(record).setExceptionDetails(apexException).setMessage(logMessage);
saveLog(SaveMethod.EVENT_BUS);
throw apexException;
}
/**
* @description Creates a new log entry with logging level == `System.LoggingLevel.ERROR`,
* automatically saves the log, and then throws the provided exception
* @param logMessage The instance of `LogMessage` to use to set the entry's message field
* @param records The list of `SObject` records to log
* @param apexException The instance of `System.Exception` to log and throw
*/
global static void exception(LogMessage logMessage, List<SObject> records, System.Exception apexException) {
error().setRecord(records).setExceptionDetails(apexException).setMessage(logMessage);
saveLog(SaveMethod.EVENT_BUS);
throw apexException;
}
/**
* @description Creates a new log entry with logging level == `System.LoggingLevel.ERROR`,
* automatically saves the log, and then throws the provided exception
* @param message The string to use to set the entry's message field
* @param apexException The instance of `System.Exception` to log and throw
*/
global static void exception(String message, System.Exception apexException) {
error().setExceptionDetails(apexException).setMessage(message);
saveLog(SaveMethod.EVENT_BUS);
throw apexException;
}
/**
* @description Creates a new log entry with logging level == `System.LoggingLevel.ERROR`,
* automatically saves the log, and then throws the provided exception
* @param message The string to use to set the entry's message field
* @param recordId The record ID of an `SObject` to log
* @param apexException The instance of `System.Exception` to log and throw
*/
global static void exception(String message, Id recordId, System.Exception apexException) {
error().setRecordId(recordId).setExceptionDetails(apexException).setMessage(message);
saveLog(SaveMethod.EVENT_BUS);
throw apexException;
}
/**
* @description Creates a new log entry with logging level == `System.LoggingLevel.ERROR`,
* automatically saves the log, and then throws the provided exception
* @param message The string to use to set the entry's message field
* @param record The `SObject` record to log
* @param apexException The instance of `System.Exception` to log and throw
*/
global static void exception(String message, SObject record, System.Exception apexException) {
error().setRecordId(record).setExceptionDetails(apexException).setMessage(message);
saveLog(SaveMethod.EVENT_BUS);
throw apexException;
}
/**
* @description Creates a new log entry with logging level == `System.LoggingLevel.ERROR`,
* automatically saves the log, and then throws the provided exception
* @param message The instance of `LogMessage` to use to set the entry's message field
* @param records The list of `SObject` records to log
* @param apexException The instance of `System.Exception` to log and throw
*/
global static void exception(String message, List<SObject> records, System.Exception apexException) {
error().setRecord(records).setExceptionDetails(apexException).setMessage(message);
saveLog(SaveMethod.EVENT_BUS);
throw apexException;
}
// ERROR logging level methods
/**
* @description Creates a new log entry with logging level == `System.LoggingLevel.ERROR`
* @param logMessage The instance of `LogMessage` to use to set the entry's message field
* @param deleteResult The instance of `Database.DeleteResult` to log
* @return The new entry's instance of `LogEntryEventBuilder`, useful for chaining methods
*/
global static LogEntryEventBuilder error(LogMessage logMessage, Database.DeleteResult deleteResult) {
return error().setDatabaseResult(deleteResult).setMessage(logMessage);
}
/**
* @description Creates a new log entry with logging level == `System.LoggingLevel.ERROR`
* @param logMessage The instance of `LogMessage` to use to set the entry's message field
* @param emptyRecycleBinResult The instance of `Database.LeadConvertResult` to log
* @return The new entry's instance of `LogEntryEventBuilder`, useful for chaining methods
*/
global static LogEntryEventBuilder error(LogMessage logMessage, Database.EmptyRecycleBinResult emptyRecycleBinResult) {
return error().setDatabaseResult(emptyRecycleBinResult).setMessage(logMessage);
}
/**
* @description Creates a new log entry with logging level == `System.LoggingLevel.ERROR`
* @param logMessage The instance of `LogMessage` to use to set the entry's message field
* @param leadConvertResult The instance of `Database.LeadConvertResult` to log
* @return The new entry's instance of `LogEntryEventBuilder`, useful for chaining methods
*/
global static LogEntryEventBuilder error(LogMessage logMessage, Database.LeadConvertResult leadConvertResult) {
return error().setDatabaseResult(leadConvertResult).setMessage(logMessage);
}
/**
* @description Creates a new log entry with logging level == `System.LoggingLevel.ERROR`
* @param logMessage The instance of `LogMessage` to use to set the entry's message field
* @param mergeResult The instance of `Database.MergeResult` to log
* @return The new entry's instance of `LogEntryEventBuilder`, useful for chaining methods
*/
global static LogEntryEventBuilder error(LogMessage logMessage, Database.MergeResult mergeResult) {
return error().setDatabaseResult(mergeResult).setMessage(logMessage);
}
/**
* @description Creates a new log entry with logging level == `System.LoggingLevel.ERROR`
* @param logMessage The instance of `LogMessage` to use to set the entry's message field
* @param saveResult The instance of `Database.SaveResult` to log
* @return The new entry's instance of `LogEntryEventBuilder`, useful for chaining methods
*/
global static LogEntryEventBuilder error(LogMessage logMessage, Database.SaveResult saveResult) {
return error().setDatabaseResult(saveResult).setMessage(logMessage);
}
/**
* @description Creates a new log entry with logging level == `System.LoggingLevel.ERROR`
* @param logMessage The instance of `LogMessage` to use to set the entry's message field
* @param undeleteResult The instance of `Database.UndeleteResult` to log
* @return The new entry's instance of `LogEntryEventBuilder`, useful for chaining methods
*/
global static LogEntryEventBuilder error(LogMessage logMessage, Database.UndeleteResult undeleteResult) {
return error().setDatabaseResult(undeleteResult).setMessage(logMessage);
}
/**
* @description Creates a new log entry with logging level == `System.LoggingLevel.ERROR`
* @param logMessage The instance of `LogMessage` to use to set the entry's message field
* @param upsertResult The instance of `Database.UpsertResult` to log
* @return The new entry's instance of `LogEntryEventBuilder`, useful for chaining methods
*/
global static LogEntryEventBuilder error(LogMessage logMessage, Database.UpsertResult upsertResult) {
return error().setDatabaseResult(upsertResult).setMessage(logMessage);
}
/**
* @description Creates a new log entry with logging level == `System.LoggingLevel.ERROR`
* @param logMessage The instance of `LogMessage` to use to set the entry's message field
* @param deleteResults The instance of `List<Database.DeleteResult>` to log
* @return The new entry's instance of `LogEntryEventBuilder`, useful for chaining methods
*/
global static LogEntryEventBuilder error(LogMessage logMessage, List<Database.DeleteResult> deleteResults) {
return error().setDatabaseResult(deleteResults).setMessage(logMessage);
}
/**
* @description Creates a new log entry with logging level == `System.LoggingLevel.ERROR`
* @param logMessage The instance of `LogMessage` to use to set the entry's message field
* @param emptyRecycleBinResults The instance of `List<Database.EmptyRecycleBinResult>` to log
* @return The new entry's instance of `LogEntryEventBuilder`, useful for chaining methods
*/
global static LogEntryEventBuilder error(LogMessage logMessage, List<Database.EmptyRecycleBinResult> emptyRecycleBinResults) {
return error().setDatabaseResult(emptyRecycleBinResults).setMessage(logMessage);
}
/**
* @description Creates a new log entry with logging level == `System.LoggingLevel.ERROR`
* @param logMessage The instance of `LogMessage` to use to set the entry's message field
* @param leadConvertResults The instance of `List<Database.LeadConvertResult>` to log
* @return The new entry's instance of `LogEntryEventBuilder`, useful for chaining methods
*/
global static LogEntryEventBuilder error(LogMessage logMessage, List<Database.LeadConvertResult> leadConvertResults) {
return error().setDatabaseResult(leadConvertResults).setMessage(logMessage);
}
/**
* @description Creates a new log entry with logging level == `System.LoggingLevel.ERROR`
* @param logMessage The instance of `LogMessage` to use to set the entry's message field
* @param mergeResults The instance of `List<Database.MergeResult>` to log
* @return The new entry's instance of `LogEntryEventBuilder`, useful for chaining methods
*/
global static LogEntryEventBuilder error(LogMessage logMessage, List<Database.MergeResult> mergeResults) {
return error().setDatabaseResult(mergeResults).setMessage(logMessage);
}
/**
* @description Creates a new log entry with logging level == `System.LoggingLevel.ERROR`
* @param logMessage The instance of `LogMessage` to use to set the entry's message field
* @param saveResults The instance of `List<Database.SaveResult>` to log
* @return The new entry's instance of `LogEntryEventBuilder`, useful for chaining methods
*/
global static LogEntryEventBuilder error(LogMessage logMessage, List<Database.SaveResult> saveResults) {
return error().setDatabaseResult(saveResults).setMessage(logMessage);
}
/**
* @description Creates a new log entry with logging level == `System.LoggingLevel.ERROR`
* @param logMessage The instance of `LogMessage` to use to set the entry's message field
* @param undeleteResults The instance of `List<Database.UndeleteResult>` to log
* @return The new entry's instance of `LogEntryEventBuilder`, useful for chaining methods
*/
global static LogEntryEventBuilder error(LogMessage logMessage, List<Database.UndeleteResult> undeleteResults) {
return error().setDatabaseResult(undeleteResults).setMessage(logMessage);
}
/**
* @description Creates a new log entry with logging level == `System.LoggingLevel.ERROR`
* @param logMessage The instance of `LogMessage` to use to set the entry's message field
* @param upsertResults The instance of `List<Database.UpsertResult>` to log
* @return The new entry's instance of `LogEntryEventBuilder`, useful for chaining methods
*/
global static LogEntryEventBuilder error(LogMessage logMessage, List<Database.UpsertResult> upsertResults) {
return error().setDatabaseResult(upsertResults).setMessage(logMessage);
}
/**
* @description Creates a new log entry with logging level == `System.LoggingLevel.ERROR`
* @param logMessage The instance of `LogMessage` to use to set the entry's message field
* @param apexException The instance of `System.Exception` to log
* @return The new entry's instance of `LogEntryEventBuilder`, useful for chaining methods
*/
global static LogEntryEventBuilder error(LogMessage logMessage, System.Exception apexException) {
return error().setExceptionDetails(apexException).setMessage(logMessage);
}
/**
* @description Creates a new log entry with logging level == `System.LoggingLevel.ERROR`
* @param logMessage The instance of `LogMessage` to use to set the entry's message field
* @param recordId The record ID of an `SObject` to log
* @param apexException The instance of `System.Exception` to log
* @return The new entry's instance of `LogEntryEventBuilder`, useful for chaining methods
*/
global static LogEntryEventBuilder error(LogMessage logMessage, Id recordId, System.Exception apexException) {
return error().setRecordId(recordId).setExceptionDetails(apexException).setMessage(logMessage);
}
/**
* @description Creates a new log entry with logging level == `System.LoggingLevel.ERROR`
* @param logMessage The instance of `LogMessage` to use to set the entry's message field
* @param recordId The record ID of an `SObject` to log
* @return The new entry's instance of `LogEntryEventBuilder`, useful for chaining methods
*/
global static LogEntryEventBuilder error(LogMessage logMessage, Id recordId) {
return error().setRecordId(recordId).setMessage(logMessage);
}
/**
* @description Creates a new log entry with logging level == `System.LoggingLevel.ERROR`
* @param logMessage The instance of `LogMessage` to use to set the entry's message field
* @param record The `SObject` record to log
* @param apexException The instance of `System.Exception` to log
* @return The new entry's instance of `LogEntryEventBuilder`, useful for chaining methods
*/
global static LogEntryEventBuilder error(LogMessage logMessage, SObject record, System.Exception apexException) {
return error().setRecordId(record).setExceptionDetails(apexException).setMessage(logMessage);
}
/**
* @description Creates a new log entry with logging level == `System.LoggingLevel.ERROR`
* @param logMessage The instance of `LogMessage` to use to set the entry's message field
* @param record The `SObject` record to log
* @return The new entry's instance of `LogEntryEventBuilder`, useful for chaining methods
*/
global static LogEntryEventBuilder error(LogMessage logMessage, SObject record) {
return error().setRecordId(record).setMessage(logMessage);
}
/**
* @description Creates a new log entry with logging level == `System.LoggingLevel.ERROR`
* @param logMessage The instance of `LogMessage` to use to set the entry's message field
* @param records The list of `SObject` records to log
* @param apexException The instance of `System.Exception` to log
* @return The new entry's instance of `LogEntryEventBuilder`, useful for chaining methods
*/
global static LogEntryEventBuilder error(LogMessage logMessage, List<SObject> records, System.Exception apexException) {
return error().setRecord(records).setExceptionDetails(apexException).setMessage(logMessage);
}
/**
* @description Creates a new log entry with logging level == `System.LoggingLevel.ERROR`
* @param logMessage The instance of `LogMessage` to use to set the entry's message field
* @param records The list of `SObject` records to log
* @return The new entry's instance of `LogEntryEventBuilder`, useful for chaining methods
*/
global static LogEntryEventBuilder error(LogMessage logMessage, List<SObject> records) {
return error().setRecord(records).setMessage(logMessage);
}
/**
* @description Creates a new log entry with logging level == `System.LoggingLevel.ERROR`
* @param logMessage The instance of `LogMessage` to use to set the entry's message field
* @return The new entry's instance of `LogEntryEventBuilder`, useful for chaining methods
*/
global static LogEntryEventBuilder error(LogMessage logMessage) {
return error().setMessage(logMessage);
}
/**
* @description Creates a new log entry with logging level == `System.LoggingLevel.ERROR`
* @param message The string to use to set the entry's message field
* @param deleteResult The instance of `Database.DeleteResult` to log
* @return The new entry's instance of `LogEntryEventBuilder`, useful for chaining methods
*/
global static LogEntryEventBuilder error(String message, Database.DeleteResult deleteResult) {
return error().setDatabaseResult(deleteResult).setMessage(message);
}
/**
* @description Creates a new log entry with logging level == `System.LoggingLevel.ERROR`
* @param message The string to use to set the entry's message field
* @param emptyRecycleBinResult The instance of `Database.LeadConvertResult` to log
* @return The new entry's instance of `LogEntryEventBuilder`, useful for chaining methods
*/
global static LogEntryEventBuilder error(String message, Database.EmptyRecycleBinResult emptyRecycleBinResult) {
return error().setDatabaseResult(emptyRecycleBinResult).setMessage(message);
}
/**
* @description Creates a new log entry with logging level == `System.LoggingLevel.ERROR`
* @param message The string to use to set the entry's message field
* @param leadConvertResult The instance of `Database.LeadConvertResult` to log
* @return The new entry's instance of `LogEntryEventBuilder`, useful for chaining methods
*/
global static LogEntryEventBuilder error(String message, Database.LeadConvertResult leadConvertResult) {
return error().setDatabaseResult(leadConvertResult).setMessage(message);
}
/**
* @description Creates a new log entry with logging level == `System.LoggingLevel.ERROR`
* @param message The string to use to set the entry's message field
* @param mergeResult The instance of `Database.MergeResult` to log
* @return The new entry's instance of `LogEntryEventBuilder`, useful for chaining methods
*/
global static LogEntryEventBuilder error(String message, Database.MergeResult mergeResult) {
return error().setDatabaseResult(mergeResult).setMessage(message);
}
/**
* @description Creates a new log entry with logging level == `System.LoggingLevel.ERROR`
* @param message The string to use to set the entry's message field
* @param saveResult The instance of `Database.SaveResult` to log
* @return The new entry's instance of `LogEntryEventBuilder`, useful for chaining methods
*/
global static LogEntryEventBuilder error(String message, Database.SaveResult saveResult) {
return error().setDatabaseResult(saveResult).setMessage(message);
}
/**
* @description Creates a new log entry with logging level == `System.LoggingLevel.ERROR`
* @param message The string to use to set the entry's message field
* @param undeleteResult The instance of `Database.UndeleteResult` to log
* @return The new entry's instance of `LogEntryEventBuilder`, useful for chaining methods
*/
global static LogEntryEventBuilder error(String message, Database.UndeleteResult undeleteResult) {
return error().setDatabaseResult(undeleteResult).setMessage(message);
}
/**
* @description Creates a new log entry with logging level == `System.LoggingLevel.ERROR`
* @param message The string to use to set the entry's message field
* @param upsertResult The instance of `Database.UpsertResult` to log
* @return The new entry's instance of `LogEntryEventBuilder`, useful for chaining methods
*/
global static LogEntryEventBuilder error(String message, Database.UpsertResult upsertResult) {
return error().setDatabaseResult(upsertResult).setMessage(message);
}
/**
* @description Creates a new log entry with logging level == `System.LoggingLevel.ERROR`
* @param message The string to use to set the entry's message field
* @param deleteResults The list of `Database.DeleteResult` instances to log
* @return The new entry's instance of `LogEntryEventBuilder`, useful for chaining methods
*/
global static LogEntryEventBuilder error(String message, List<Database.DeleteResult> deleteResults) {
return error().setDatabaseResult(deleteResults).setMessage(message);
}
/**
* @description Creates a new log entry with logging level == `System.LoggingLevel.ERROR`
* @param message The string to use to set the entry's message field
* @param emptyRecycleBinResults The instance of `List<Database.EmptyRecycleBinResult>` to log
* @return The new entry's instance of `LogEntryEventBuilder`, useful for chaining methods
*/
global static LogEntryEventBuilder error(String message, List<Database.EmptyRecycleBinResult> emptyRecycleBinResults) {
return error().setDatabaseResult(emptyRecycleBinResults).setMessage(message);
}
/**
* @description Creates a new log entry with logging level == `System.LoggingLevel.ERROR`
* @param message The string to use to set the entry's message field
* @param leadConvertResults The instance of `List<Database.LeadConvertResult>` to log
* @return The new entry's instance of `LogEntryEventBuilder`, useful for chaining methods
*/
global static LogEntryEventBuilder error(String message, List<Database.LeadConvertResult> leadConvertResults) {
return error().setDatabaseResult(leadConvertResults).setMessage(message);
}
/**
* @description Creates a new log entry with logging level == `System.LoggingLevel.ERROR`
* @param message The string to use to set the entry's message field
* @param mergeResults The list of `Database.MergeResult` instances to log
* @return The new entry's instance of `LogEntryEventBuilder`, useful for chaining methods
*/
global static LogEntryEventBuilder error(String message, List<Database.MergeResult> mergeResults) {
return error().setDatabaseResult(mergeResults).setMessage(message);
}
/**
* @description Creates a new log entry with logging level == `System.LoggingLevel.ERROR`
* @param message The string to use to set the entry's message field
* @param saveResults The list of `Database.SaveResult` instances to log
* @return The new entry's instance of `LogEntryEventBuilder`, useful for chaining methods
*/
global static LogEntryEventBuilder error(String message, List<Database.SaveResult> saveResults) {
return error().setDatabaseResult(saveResults).setMessage(message);
}
/**
* @description Creates a new log entry with logging level == `System.LoggingLevel.ERROR`
* @param message The string to use to set the entry's message field
* @param undeleteResults The list of `Database.UndeleteResult` instances to log
* @return The new entry's instance of `LogEntryEventBuilder`, useful for chaining methods
*/
global static LogEntryEventBuilder error(String message, List<Database.UndeleteResult> undeleteResults) {
return error().setDatabaseResult(undeleteResults).setMessage(message);
}
/**
* @description Creates a new log entry with logging level == `System.LoggingLevel.ERROR`
* @param message The string to use to set the entry's message field
* @param upsertResults The list of `Database.UpsertResult` instances to log
* @return The new entry's instance of `LogEntryEventBuilder`, useful for chaining methods
*/
global static LogEntryEventBuilder error(String message, List<Database.UpsertResult> upsertResults) {
return error().setDatabaseResult(upsertResults).setMessage(message);
}
/**
* @description Creates a new log entry with logging level == `System.LoggingLevel.ERROR`
* @param message The string to use to set the entry's message field
* @param apexException The instance of `System.Exception` to log
* @return The new entry's instance of `LogEntryEventBuilder`, useful for chaining methods
*/
global static LogEntryEventBuilder error(String message, System.Exception apexException) {
return error().setExceptionDetails(apexException).setMessage(message);
}
/**
* @description Creates a new log entry with logging level == `System.LoggingLevel.ERROR`
* @param message The string to use to set the entry's message field
* @param recordId The record ID of an `SObject` to log
* @param apexException The instance of `System.Exception` to log
* @return The new entry's instance of `LogEntryEventBuilder`, useful for chaining methods
*/
global static LogEntryEventBuilder error(String message, Id recordId, System.Exception apexException) {
return error().setRecordId(recordId).setExceptionDetails(apexException).setMessage(message);
}
/**
* @description Creates a new log entry with logging level == `System.LoggingLevel.ERROR`
* @param message The string to use to set the entry's message field
* @param recordId The record ID of an `SObject` to log
* @return The new entry's instance of `LogEntryEventBuilder`, useful for chaining methods
*/
global static LogEntryEventBuilder error(String message, Id recordId) {
return error().setRecordId(recordId).setMessage(message);
}
/**
* @description Creates a new log entry with logging level == `System.LoggingLevel.ERROR`
* @param message The string to use to set the entry's message field
* @param record The `SObject` record to log
* @param apexException The instance of `System.Exception` to log
* @return The new entry's instance of `LogEntryEventBuilder`, useful for chaining methods